import cv2
import argparse
import copy
import time
import psutil
import onnxruntime
import numpy as np
from skimage import transform as trans
from typing import Optional, List, Tuple


class RetinaFaceONNX(object):
    def __init__(
        self,
        model_path: Optional[str] = 'retinaface_mbn025_with_postprocess_480x640_max1000_th0.70.onnx',
        providers: Optional[List] = [
            (
                'TensorrtExecutionProvider', {
                    'trt_engine_cache_enable': True,
                    'trt_engine_cache_path': '.',
                    'trt_fp16_enable': True,
                }
            ),
            'CUDAExecutionProvider',
            'CPUExecutionProvider',
        ],
    ):
        """RetinaFaceONNX

        Parameters
        ----------
        model_path: Optional[str]
            ONNX file path

        providers: Optional[List]
            Name of onnx execution providers
        """
        # Model loading
        session_option = onnxruntime.SessionOptions()
        session_option.log_severity_level = 3
        session_option.intra_op_num_threads = psutil.cpu_count(logical=True) - 1
        self.onnx_session = onnxruntime.InferenceSession(
            model_path,
            sess_options=session_option,
            providers=providers,
        )
        self.providers = self.onnx_session.get_providers()

        self.input_shapes = [
            input.shape for input in self.onnx_session.get_inputs()
        ]
        self.input_names = [
            input.name for input in self.onnx_session.get_inputs()
        ]
        self.output_names = [
            output.name for output in self.onnx_session.get_outputs()
        ]
        self.mean = np.asarray([104, 117, 123], dtype=np.float32)

    def __call__(
        self,
        image: np.ndarray,
    ) -> np.ndarray:
        """

        Parameters
        ----------
        image: np.ndarray
            Entire image

        Returns
        -------
        batchno_classid_score_x1y1x2y2_landms: np.ndarray
            [N, [batchno, classid, score, x1, y1, x2, y2, landms0, ..., landms9]]
        """
        temp_image = copy.deepcopy(image)

        # PreProcess
        resized_image = \
            self.__preprocess(
                temp_image,
            )

        # Inference
        inferece_image = np.asarray([resized_image], dtype=np.float32)
        batchno_classid_score_x1y1x2y2_landms = \
            self.onnx_session.run(
                self.output_names,
                {input_name: inferece_image for input_name in self.input_names},
            )[0]

        return batchno_classid_score_x1y1x2y2_landms

    def __preprocess(
        self,
        image: np.ndarray,
        swap: Optional[Tuple[int,int,int]] = (2, 0, 1),
    ) -> np.ndarray:
        """__preprocess

        Parameters
        ----------
        image: np.ndarray
            Entire image

        swap: tuple
            HWC to CHW: (2,0,1)
            CHW to HWC: (1,2,0)
            HWC to HWC: (0,1,2)
            CHW to CHW: (0,1,2)

        Returns
        -------
        resized_image: np.ndarray
            Resized and normalized image.
        """
        # Normalization + BGR->RGB
        resized_image = cv2.resize(
            image,
            (
                int(self.input_shapes[0][3]),
                int(self.input_shapes[0][2]),
            )
        )
        resized_image = resized_image[..., ::-1]
        resized_image = (resized_image - self.mean)
        resized_image = resized_image.transpose(swap)
        resized_image = \
            np.ascontiguousarray(
                resized_image,
                dtype=np.float32,
            )
        return resized_image

def angles_from_vec(vec):
    x, y, z = -vec[2], vec[1], -vec[0]
    theta = np.arctan2(y, x)
    phi = np.arctan2(np.sqrt(x**2 + y**2), z) - np.pi/2
    theta_x, theta_y = phi, theta
    return theta_x, theta_y

def vec_from_eye(eye, iris_lms_idx):
    p_iris = eye[iris_lms_idx] - eye[:32].mean(axis=0)
    vec = p_iris.mean(axis=0)
    vec /= np.linalg.norm(vec, axis=0)
    return vec

def angles_and_vec_from_eye(eye, iris_lms_idx):

    vec = vec_from_eye(eye, iris_lms_idx)
    theta_x, theta_y = angles_from_vec(vec)
    return theta_x, theta_y, vec

def vec_from_angles(rx, ry):
    rx = np.deg2rad(rx)
    ry = np.deg2rad(ry)
    x1 = np.sin(np.pi/2 + rx) * np.cos(ry)
    y1 = np.sin(np.pi/2 + rx) * np.sin(ry)
    z1 = np.cos(np.pi/2 + rx)
    x, y, z = -z1, y1, -x1
    vec = np.array([x, y, z])
    vec /= np.linalg.norm(vec, axis=0)
    return vec

def transform(data, center, output_size, scale, rotation):
    scale_ratio = scale
    rot = float(rotation) * np.pi / 180.0
    t1 = trans.SimilarityTransform(scale=scale_ratio)
    cx = center[0] * scale_ratio
    cy = center[1] * scale_ratio
    t2 = trans.SimilarityTransform(
        translation=(-1 * cx, -1 * cy)
    )
    t3 = trans.SimilarityTransform(
        rotation=rot
    )
    t4 = trans.SimilarityTransform(
        translation=(
            output_size / 2,
            output_size / 2
        )
    )
    t = t1 + t2 + t3 + t4
    M = t.params[0:2]
    cropped = cv2.warpAffine(
        data,
        M,
        (output_size, output_size),
        borderValue=0.0
    )
    return cropped, M

def trans_points2d(pts, M):
    new_pts = np.zeros(shape=pts.shape, dtype=np.float32)
    for i in range(pts.shape[0]):
        pt = pts[i]
        new_pt = np.array([pt[0], pt[1], 1.], dtype=np.float32)
        new_pt = np.dot(M, new_pt)
        new_pts[i] = new_pt[0:2]
    return new_pts


def trans_points3d(pts, M):
    scale = np.sqrt(M[0][0] * M[0][0] + M[0][1] * M[0][1])
    new_pts = np.zeros(shape=pts.shape, dtype=np.float32)
    for i in range(pts.shape[0]):
        pt = pts[i]
        new_pt = np.array([pt[0], pt[1], 1.], dtype=np.float32)
        new_pt = np.dot(M, new_pt)
        new_pts[i][0:2] = new_pt[0:2]
        new_pts[i][2] = pts[i][2] * scale
    return new_pts

def trans_points(pts, M):
    if pts.shape[1] == 2:
        return trans_points2d(pts, M)
    else:
        return trans_points3d(pts, M)


class GazeHandler():
    def __init__(
        self,
        detector,
        model_path='generalizing_gaze_estimation_with_weak_supervision_from_synthetic_views_Nx3x160x160.onnx',
        providers: Optional[List] = [
            (
                'TensorrtExecutionProvider', {
                    'trt_engine_cache_enable': True,
                    'trt_engine_cache_path': '.',
                    'trt_fp16_enable': True,
                }
            ),
            'CUDAExecutionProvider',
            'CPUExecutionProvider',
        ],
        enable_3d_rendering = False,
    ):
        self.detector = detector
        self.tri481= np.asarray(
            [
                [ 32,   0,  33],
                [ 33,   1,  34],
                [ 34,   2,  35],
                [ 35,   3,  36],
                [ 36,   4,  37],
                [ 37,   5,  38],
                [ 38,   6,  39],
                [ 39,   7,  40],
                [ 40,   8,  41],
                [ 41,   9,  42],
                [ 42,  10,  43],
                [ 43,  11,  44],
                [ 44,  12,  45],
                [ 45,  13,  46],
                [ 46,  14,  47],
                [ 47,  15,  48],
                [ 48,  16,  49],
                [ 49,  17,  50],
                [ 50,  18,  51],
                [ 51,  19,  52],
                [ 52,  20,  53],
                [ 53,  21,  54],
                [ 54,  22,  55],
                [ 55,  23,  56],
                [ 56,  24,  57],
                [ 57,  25,  58],
                [ 58,  26,  59],
                [ 59,  27,  60],
                [ 60,  28,  61],
                [ 61,  29,  62],
                [ 62,  30,  63],
                [ 63,  31,  32],
                [  1,  33,   0],
                [  2,  34,   1],
                [  3,  35,   2],
                [  4,  36,   3],
                [  5,  37,   4],
                [  6,  38,   5],
                [  7,  39,   6],
                [  8,  40,   7],
                [  9,  41,   8],
                [ 10,  42,   9],
                [ 11,  43,  10],
                [ 12,  44,  11],
                [ 13,  45,  12],
                [ 14,  46,  13],
                [ 15,  47,  14],
                [ 16,  48,  15],
                [ 17,  49,  16],
                [ 18,  50,  17],
                [ 19,  51,  18],
                [ 20,  52,  19],
                [ 21,  53,  20],
                [ 22,  54,  21],
                [ 23,  55,  22],
                [ 24,  56,  23],
                [ 25,  57,  24],
                [ 26,  58,  25],
                [ 27,  59,  26],
                [ 28,  60,  27],
                [ 29,  61,  28],
                [ 30,  62,  29],
                [ 31,  63,  30],
                [  0,  32,  31],
                [ 64,  32,  65],
                [ 65,  33,  66],
                [ 66,  34,  67],
                [ 67,  35,  68],
                [ 68,  36,  69],
                [ 69,  37,  70],
                [ 70,  38,  71],
                [ 71,  39,  72],
                [ 72,  40,  73],
                [ 73,  41,  74],
                [ 74,  42,  75],
                [ 75,  43,  76],
                [ 76,  44,  77],
                [ 77,  45,  78],
                [ 78,  46,  79],
                [ 79,  47,  80],
                [ 80,  48,  81],
                [ 81,  49,  82],
                [ 82,  50,  83],
                [ 83,  51,  84],
                [ 84,  52,  85],
                [ 85,  53,  86],
                [ 86,  54,  87],
                [ 87,  55,  88],
                [ 88,  56,  89],
                [ 89,  57,  90],
                [ 90,  58,  91],
                [ 91,  59,  92],
                [ 92,  60,  93],
                [ 93,  61,  94],
                [ 94,  62,  95],
                [ 95,  63,  64],
                [ 33,  65,  32],
                [ 34,  66,  33],
                [ 35,  67,  34],
                [ 36,  68,  35],
                [ 37,  69,  36],
                [ 38,  70,  37],
                [ 39,  71,  38],
                [ 40,  72,  39],
                [ 41,  73,  40],
                [ 42,  74,  41],
                [ 43,  75,  42],
                [ 44,  76,  43],
                [ 45,  77,  44],
                [ 46,  78,  45],
                [ 47,  79,  46],
                [ 48,  80,  47],
                [ 49,  81,  48],
                [ 50,  82,  49],
                [ 51,  83,  50],
                [ 52,  84,  51],
                [ 53,  85,  52],
                [ 54,  86,  53],
                [ 55,  87,  54],
                [ 56,  88,  55],
                [ 57,  89,  56],
                [ 58,  90,  57],
                [ 59,  91,  58],
                [ 60,  92,  59],
                [ 61,  93,  60],
                [ 62,  94,  61],
                [ 63,  95,  62],
                [ 32,  64,  63],
                [ 96,  64,  97],
                [ 97,  65,  98],
                [ 98,  66,  99],
                [ 99,  67, 100],
                [100,  68, 101],
                [101,  69, 102],
                [102,  70, 103],
                [103,  71, 104],
                [104,  72, 105],
                [105,  73, 106],
                [106,  74, 107],
                [107,  75, 108],
                [108,  76, 109],
                [109,  77, 110],
                [110,  78, 111],
                [111,  79, 112],
                [112,  80, 113],
                [113,  81, 114],
                [114,  82, 115],
                [115,  83, 116],
                [116,  84, 117],
                [117,  85, 118],
                [118,  86, 119],
                [119,  87, 120],
                [120,  88, 121],
                [121,  89, 122],
                [122,  90, 123],
                [123,  91, 124],
                [124,  92, 125],
                [125,  93, 126],
                [126,  94, 127],
                [127,  95,  96],
                [ 65,  97,  64],
                [ 66,  98,  65],
                [ 67,  99,  66],
                [ 68, 100,  67],
                [ 69, 101,  68],
                [ 70, 102,  69],
                [ 71, 103,  70],
                [ 72, 104,  71],
                [ 73, 105,  72],
                [ 74, 106,  73],
                [ 75, 107,  74],
                [ 76, 108,  75],
                [ 77, 109,  76],
                [ 78, 110,  77],
                [ 79, 111,  78],
                [ 80, 112,  79],
                [ 81, 113,  80],
                [ 82, 114,  81],
                [ 83, 115,  82],
                [ 84, 116,  83],
                [ 85, 117,  84],
                [ 86, 118,  85],
                [ 87, 119,  86],
                [ 88, 120,  87],
                [ 89, 121,  88],
                [ 90, 122,  89],
                [ 91, 123,  90],
                [ 92, 124,  91],
                [ 93, 125,  92],
                [ 94, 126,  93],
                [ 95, 127,  94],
                [ 64,  96,  95],
                [224,  96, 225],
                [225,  97, 226],
                [226,  98, 227],
                [227,  99, 228],
                [228, 100, 229],
                [229, 101, 230],
                [230, 102, 231],
                [231, 103, 232],
                [232, 104, 233],
                [233, 105, 234],
                [234, 106, 235],
                [235, 107, 236],
                [236, 108, 237],
                [237, 109, 238],
                [238, 110, 239],
                [239, 111, 240],
                [240, 112, 241],
                [241, 113, 242],
                [242, 114, 243],
                [243, 115, 244],
                [244, 116, 245],
                [245, 117, 246],
                [246, 118, 247],
                [247, 119, 248],
                [248, 120, 249],
                [249, 121, 250],
                [250, 122, 251],
                [251, 123, 252],
                [252, 124, 253],
                [253, 125, 254],
                [254, 126, 255],
                [255, 127, 224],
                [ 97, 225,  96],
                [ 98, 226,  97],
                [ 99, 227,  98],
                [100, 228,  99],
                [101, 229, 100],
                [102, 230, 101],
                [103, 231, 102],
                [104, 232, 103],
                [105, 233, 104],
                [106, 234, 105],
                [107, 235, 106],
                [108, 236, 107],
                [109, 237, 108],
                [110, 238, 109],
                [111, 239, 110],
                [112, 240, 111],
                [113, 241, 112],
                [114, 242, 113],
                [115, 243, 114],
                [116, 244, 115],
                [117, 245, 116],
                [118, 246, 117],
                [119, 247, 118],
                [120, 248, 119],
                [121, 249, 120],
                [122, 250, 121],
                [123, 251, 122],
                [124, 252, 123],
                [125, 253, 124],
                [126, 254, 125],
                [127, 255, 126],
                [ 96, 224, 127],
                [  0, 288,   1],
                [  1, 289,   2],
                [  2, 290,   3],
                [  3, 291,   4],
                [  4, 292,   5],
                [  5, 293,   6],
                [  6, 294,   7],
                [  7, 295,   8],
                [  8, 296,   9],
                [  9, 297,  10],
                [ 10, 298,  11],
                [ 11, 299,  12],
                [ 12, 300,  13],
                [ 13, 301,  14],
                [ 14, 302,  15],
                [ 15, 303,  16],
                [ 16, 304,  17],
                [ 17, 305,  18],
                [ 18, 306,  19],
                [ 19, 307,  20],
                [ 20, 308,  21],
                [ 21, 309,  22],
                [ 22, 310,  23],
                [ 23, 311,  24],
                [ 24, 312,  25],
                [ 25, 313,  26],
                [ 26, 314,  27],
                [ 27, 315,  28],
                [ 28, 316,  29],
                [ 29, 317,  30],
                [ 30, 318,  31],
                [ 31, 319,   0],
                [289,   1, 288],
                [290,   2, 289],
                [291,   3, 290],
                [292,   4, 291],
                [293,   5, 292],
                [294,   6, 293],
                [295,   7, 294],
                [296,   8, 295],
                [297,   9, 296],
                [298,  10, 297],
                [299,  11, 298],
                [300,  12, 299],
                [301,  13, 300],
                [302,  14, 301],
                [303,  15, 302],
                [304,  16, 303],
                [305,  17, 304],
                [306,  18, 305],
                [307,  19, 306],
                [308,  20, 307],
                [309,  21, 308],
                [310,  22, 309],
                [311,  23, 310],
                [312,  24, 311],
                [313,  25, 312],
                [314,  26, 313],
                [315,  27, 314],
                [316,  28, 315],
                [317,  29, 316],
                [318,  30, 317],
                [319,  31, 318],
                [288,   0, 319],
                [288, 320, 289],
                [289, 321, 290],
                [290, 322, 291],
                [291, 323, 292],
                [292, 324, 293],
                [293, 325, 294],
                [294, 326, 295],
                [295, 327, 296],
                [296, 328, 297],
                [297, 329, 298],
                [298, 330, 299],
                [299, 331, 300],
                [300, 332, 301],
                [301, 333, 302],
                [302, 334, 303],
                [303, 335, 304],
                [304, 336, 305],
                [305, 337, 306],
                [306, 338, 307],
                [307, 339, 308],
                [308, 340, 309],
                [309, 341, 310],
                [310, 342, 311],
                [311, 343, 312],
                [312, 344, 313],
                [313, 345, 314],
                [314, 346, 315],
                [315, 347, 316],
                [316, 348, 317],
                [317, 349, 318],
                [318, 350, 319],
                [319, 351, 288],
                [321, 289, 320],
                [322, 290, 321],
                [323, 291, 322],
                [324, 292, 323],
                [325, 293, 324],
                [326, 294, 325],
                [327, 295, 326],
                [328, 296, 327],
                [329, 297, 328],
                [330, 298, 329],
                [331, 299, 330],
                [332, 300, 331],
                [333, 301, 332],
                [334, 302, 333],
                [335, 303, 334],
                [336, 304, 335],
                [337, 305, 336],
                [338, 306, 337],
                [339, 307, 338],
                [340, 308, 339],
                [341, 309, 340],
                [342, 310, 341],
                [343, 311, 342],
                [344, 312, 343],
                [345, 313, 344],
                [346, 314, 345],
                [347, 315, 346],
                [348, 316, 347],
                [349, 317, 348],
                [350, 318, 349],
                [351, 319, 350],
                [320, 288, 351],
                [320, 352, 321],
                [321, 353, 322],
                [322, 354, 323],
                [323, 355, 324],
                [324, 356, 325],
                [325, 357, 326],
                [326, 358, 327],
                [327, 359, 328],
                [328, 360, 329],
                [329, 361, 330],
                [330, 362, 331],
                [331, 363, 332],
                [332, 364, 333],
                [333, 365, 334],
                [334, 366, 335],
                [335, 367, 336],
                [336, 368, 337],
                [337, 369, 338],
                [338, 370, 339],
                [339, 371, 340],
                [340, 372, 341],
                [341, 373, 342],
                [342, 374, 343],
                [343, 375, 344],
                [344, 376, 345],
                [345, 377, 346],
                [346, 378, 347],
                [347, 379, 348],
                [348, 380, 349],
                [349, 381, 350],
                [350, 382, 351],
                [351, 383, 320],
                [353, 321, 352],
                [354, 322, 353],
                [355, 323, 354],
                [356, 324, 355],
                [357, 325, 356],
                [358, 326, 357],
                [359, 327, 358],
                [360, 328, 359],
                [361, 329, 360],
                [362, 330, 361],
                [363, 331, 362],
                [364, 332, 363],
                [365, 333, 364],
                [366, 334, 365],
                [367, 335, 366],
                [368, 336, 367],
                [369, 337, 368],
                [370, 338, 369],
                [371, 339, 370],
                [372, 340, 371],
                [373, 341, 372],
                [374, 342, 373],
                [375, 343, 374],
                [376, 344, 375],
                [377, 345, 376],
                [378, 346, 377],
                [379, 347, 378],
                [380, 348, 379],
                [381, 349, 380],
                [382, 350, 381],
                [383, 351, 382],
                [352, 320, 383],
                [192, 224, 193],
                [193, 225, 194],
                [194, 226, 195],
                [195, 227, 196],
                [196, 228, 197],
                [197, 229, 198],
                [198, 230, 199],
                [199, 231, 200],
                [200, 232, 201],
                [201, 233, 202],
                [202, 234, 203],
                [203, 235, 204],
                [204, 236, 205],
                [205, 237, 206],
                [206, 238, 207],
                [207, 239, 208],
                [208, 240, 209],
                [209, 241, 210],
                [210, 242, 211],
                [211, 243, 212],
                [212, 244, 213],
                [213, 245, 214],
                [214, 246, 215],
                [215, 247, 216],
                [216, 248, 217],
                [217, 249, 218],
                [218, 250, 219],
                [219, 251, 220],
                [220, 252, 221],
                [221, 253, 222],
                [222, 254, 223],
                [223, 255, 192],
                [225, 193, 224],
                [226, 194, 225],
                [227, 195, 226],
                [228, 196, 227],
                [229, 197, 228],
                [230, 198, 229],
                [231, 199, 230],
                [232, 200, 231],
                [233, 201, 232],
                [234, 202, 233],
                [235, 203, 234],
                [236, 204, 235],
                [237, 205, 236],
                [238, 206, 237],
                [239, 207, 238],
                [240, 208, 239],
                [241, 209, 240],
                [242, 210, 241],
                [243, 211, 242],
                [244, 212, 243],
                [245, 213, 244],
                [246, 214, 245],
                [247, 215, 246],
                [248, 216, 247],
                [249, 217, 248],
                [250, 218, 249],
                [251, 219, 250],
                [252, 220, 251],
                [253, 221, 252],
                [254, 222, 253],
                [255, 223, 254],
                [224, 192, 255],
                [266, 192, 256],
                [193, 256, 192],
                [256, 193, 257],
                [194, 257, 193],
                [257, 194, 283],
                [195, 283, 194],
                [283, 195, 278],
                [196, 278, 195],
                [278, 196, 272],
                [197, 272, 196],
                [272, 197, 268],
                [198, 268, 197],
                [268, 198, 260],
                [199, 260, 198],
                [260, 199, 261],
                [200, 261, 199],
                [261, 200, 285],
                [201, 285, 200],
                [285, 201, 280],
                [202, 280, 201],
                [280, 202, 274],
                [203, 274, 202],
                [274, 203, 270],
                [204, 270, 203],
                [270, 204, 264],
                [205, 264, 204],
                [264, 205, 265],
                [206, 265, 205],
                [265, 206, 287],
                [207, 287, 206],
                [287, 207, 282],
                [208, 282, 207],
                [282, 208, 277],
                [209, 277, 208],
                [277, 209, 271],
                [210, 271, 209],
                [271, 210, 267],
                [211, 267, 210],
                [267, 211, 259],
                [212, 259, 211],
                [259, 212, 258],
                [213, 258, 212],
                [258, 213, 284],
                [214, 284, 213],
                [284, 214, 279],
                [215, 279, 214],
                [279, 215, 273],
                [216, 273, 215],
                [273, 216, 269],
                [217, 269, 216],
                [269, 217, 262],
                [218, 262, 217],
                [262, 218, 263],
                [219, 263, 218],
                [263, 219, 286],
                [220, 286, 219],
                [286, 220, 281],
                [221, 281, 220],
                [281, 221, 275],
                [222, 275, 221],
                [275, 222, 276],
                [223, 276, 222],
                [276, 223, 266],
                [192, 266, 223],
                [128, 266, 129],
                [129, 256, 130],
                [130, 257, 131],
                [131, 283, 132],
                [132, 278, 133],
                [133, 272, 134],
                [134, 268, 135],
                [135, 260, 136],
                [136, 261, 137],
                [137, 285, 138],
                [138, 280, 139],
                [139, 274, 140],
                [140, 270, 141],
                [141, 264, 142],
                [142, 265, 143],
                [143, 287, 144],
                [144, 282, 145],
                [145, 277, 146],
                [146, 271, 147],
                [147, 267, 148],
                [148, 259, 149],
                [149, 258, 150],
                [150, 284, 151],
                [151, 279, 152],
                [152, 273, 153],
                [153, 269, 154],
                [154, 262, 155],
                [155, 263, 156],
                [156, 286, 157],
                [157, 281, 158],
                [158, 275, 159],
                [159, 276, 128],
                [256, 129, 266],
                [257, 130, 256],
                [283, 131, 257],
                [278, 132, 283],
                [272, 133, 278],
                [268, 134, 272],
                [260, 135, 268],
                [261, 136, 260],
                [285, 137, 261],
                [280, 138, 285],
                [274, 139, 280],
                [270, 140, 274],
                [264, 141, 270],
                [265, 142, 264],
                [287, 143, 265],
                [282, 144, 287],
                [277, 145, 282],
                [271, 146, 277],
                [267, 147, 271],
                [259, 148, 267],
                [258, 149, 259],
                [284, 150, 258],
                [279, 151, 284],
                [273, 152, 279],
                [269, 153, 273],
                [262, 154, 269],
                [263, 155, 262],
                [286, 156, 263],
                [281, 157, 286],
                [275, 158, 281],
                [276, 159, 275],
                [266, 128, 276],
                [353, 426, 416],
                [354, 416, 417],
                [355, 417, 443],
                [356, 443, 438],
                [357, 438, 432],
                [358, 432, 428],
                [359, 428, 420],
                [360, 420, 421],
                [361, 421, 445],
                [362, 445, 440],
                [363, 440, 434],
                [364, 434, 430],
                [365, 430, 424],
                [366, 424, 425],
                [367, 425, 447],
                [368, 447, 442],
                [369, 442, 437],
                [370, 437, 431],
                [371, 431, 427],
                [372, 427, 418],
                [373, 418, 419],
                [374, 419, 444],
                [375, 444, 439],
                [376, 439, 433],
                [377, 433, 429],
                [378, 429, 422],
                [379, 422, 423],
                [380, 423, 446],
                [381, 446, 441],
                [382, 441, 435],
                [383, 435, 436],
                [352, 436, 426],
                [426, 353, 352],
                [416, 354, 353],
                [417, 355, 354],
                [443, 356, 355],
                [438, 357, 356],
                [432, 358, 357],
                [428, 359, 358],
                [420, 360, 359],
                [421, 361, 360],
                [445, 362, 361],
                [440, 363, 362],
                [434, 364, 363],
                [430, 365, 364],
                [424, 366, 365],
                [425, 367, 366],
                [447, 368, 367],
                [442, 369, 368],
                [437, 370, 369],
                [431, 371, 370],
                [427, 372, 371],
                [418, 373, 372],
                [419, 374, 373],
                [444, 375, 374],
                [439, 376, 375],
                [433, 377, 376],
                [429, 378, 377],
                [422, 379, 378],
                [423, 380, 379],
                [446, 381, 380],
                [441, 382, 381],
                [435, 383, 382],
                [436, 352, 383],
                [416, 384, 385],
                [417, 385, 386],
                [443, 386, 387],
                [438, 387, 388],
                [432, 388, 389],
                [428, 389, 390],
                [420, 390, 391],
                [421, 391, 392],
                [445, 392, 393],
                [440, 393, 394],
                [434, 394, 395],
                [430, 395, 396],
                [424, 396, 397],
                [425, 397, 398],
                [447, 398, 399],
                [442, 399, 400],
                [437, 400, 401],
                [431, 401, 402],
                [427, 402, 403],
                [418, 403, 404],
                [419, 404, 405],
                [444, 405, 406],
                [439, 406, 407],
                [433, 407, 408],
                [429, 408, 409],
                [422, 409, 410],
                [423, 410, 411],
                [446, 411, 412],
                [441, 412, 413],
                [435, 413, 414],
                [436, 414, 415],
                [426, 415, 384],
                [384, 416, 426],
                [385, 417, 416],
                [386, 443, 417],
                [387, 438, 443],
                [388, 432, 438],
                [389, 428, 432],
                [390, 420, 428],
                [391, 421, 420],
                [392, 445, 421],
                [393, 440, 445],
                [394, 434, 440],
                [395, 430, 434],
                [396, 424, 430],
                [397, 425, 424],
                [398, 447, 425],
                [399, 442, 447],
                [400, 437, 442],
                [401, 431, 437],
                [402, 427, 431],
                [403, 418, 427],
                [404, 419, 418],
                [405, 444, 419],
                [406, 439, 444],
                [407, 433, 439],
                [408, 429, 433],
                [409, 422, 429],
                [410, 423, 422],
                [411, 446, 423],
                [412, 441, 446],
                [413, 435, 441],
                [414, 436, 435],
                [415, 426, 436],
                [128, 129, 161],
                [128, 161, 160],
                [129, 130, 162],
                [129, 162, 161],
                [130, 131, 163],
                [130, 163, 162],
                [131, 132, 164],
                [131, 164, 163],
                [132, 133, 165],
                [132, 165, 164],
                [133, 134, 166],
                [133, 166, 165],
                [134, 135, 167],
                [134, 167, 166],
                [135, 136, 168],
                [135, 168, 167],
                [136, 137, 169],
                [136, 169, 168],
                [137, 138, 170],
                [137, 170, 169],
                [138, 139, 171],
                [138, 171, 170],
                [139, 140, 172],
                [139, 172, 171],
                [140, 141, 173],
                [140, 173, 172],
                [141, 142, 174],
                [141, 174, 173],
                [142, 143, 175],
                [142, 175, 174],
                [143, 144, 176],
                [143, 176, 175],
                [144, 145, 177],
                [144, 177, 176],
                [145, 146, 178],
                [145, 178, 177],
                [146, 147, 179],
                [146, 179, 178],
                [147, 148, 180],
                [147, 180, 179],
                [148, 149, 181],
                [148, 181, 180],
                [149, 150, 182],
                [149, 182, 181],
                [150, 151, 183],
                [150, 183, 182],
                [151, 152, 184],
                [151, 184, 183],
                [152, 153, 185],
                [152, 185, 184],
                [153, 154, 186],
                [153, 186, 185],
                [154, 155, 187],
                [154, 187, 186],
                [155, 156, 188],
                [155, 188, 187],
                [156, 157, 189],
                [156, 189, 188],
                [157, 158, 190],
                [157, 190, 189],
                [158, 159, 191],
                [158, 191, 190],
                [159, 128, 160],
                [159, 160, 191],
                [449, 410, 448],
                [410, 409, 448],
                [450, 411, 449],
                [411, 410, 449],
                [451, 412, 450],
                [412, 411, 450],
                [452, 413, 451],
                [413, 412, 451],
                [453, 414, 452],
                [414, 413, 452],
                [454, 415, 453],
                [415, 414, 453],
                [456, 386, 455],
                [386, 385, 455],
                [457, 387, 456],
                [387, 386, 456],
                [458, 388, 457],
                [388, 387, 457],
                [459, 389, 458],
                [389, 388, 458],
                [460, 390, 459],
                [390, 389, 459],
                [461, 391, 460],
                [391, 390, 460],
                [462, 384, 454],
                [384, 415, 454],
                [462, 455, 385],
                [462, 385, 384],
                [464, 394, 463],
                [394, 393, 463],
                [465, 395, 464],
                [395, 394, 464],
                [466, 396, 465],
                [396, 395, 465],
                [467, 397, 466],
                [397, 396, 466],
                [468, 398, 467],
                [398, 397, 467],
                [469, 399, 468],
                [399, 398, 468],
                [463, 393, 470],
                [393, 392, 470],
                [391, 461, 392],
                [461, 470, 392],
                [472, 402, 471],
                [402, 401, 471],
                [473, 403, 472],
                [403, 402, 472],
                [474, 404, 473],
                [404, 403, 473],
                [475, 405, 474],
                [405, 404, 474],
                [476, 406, 475],
                [406, 405, 475],
                [477, 407, 476],
                [407, 406, 476],
                [478, 408, 477],
                [408, 407, 477],
                [478, 448, 408],
                [448, 409, 408],
                [471, 401, 479],
                [401, 400, 479],
                [469, 479, 400],
                [469, 400, 399],
                [448, 478, 480],
                [449, 448, 480],
                [450, 449, 480],
                [451, 450, 480],
                [452, 451, 480],
                [453, 452, 480],
                [454, 453, 480],
                [462, 454, 480],
                [455, 462, 480],
                [456, 455, 480],
                [457, 456, 480],
                [458, 457, 480],
                [459, 458, 480],
                [460, 459, 480],
                [461, 460, 480],
                [470, 461, 480],
                [463, 470, 480],
                [464, 463, 480],
                [465, 464, 480],
                [466, 465, 480],
                [467, 466, 480],
                [468, 467, 480],
                [469, 468, 480],
                [479, 469, 480],
                [471, 479, 480],
                [472, 471, 480],
                [473, 472, 480],
                [474, 473, 480],
                [475, 474, 480],
                [476, 475, 480],
                [477, 476, 480],
                [478, 477, 480],
            ],
            dtype=np.int64,
        )
        self.iris_idx_481 = np.asarray([248, 252, 224, 228, 232, 236, 240, 244], dtype=np.int64)
        self.mean_l = np.asarray(
            [
                [-9.90011310e-01, -3.73684078e-04,  1.14803439e-02],
                [-9.68485708e-01, -1.92106212e-04,  2.06351758e-01],
                [-9.09747412e-01, -3.15642525e-06,  3.93283721e-01],
                [-8.16051650e-01,  1.85922406e-04,  5.65112303e-01],
                [-6.90988553e-01,  3.67858636e-04,  7.15223492e-01],
                [-5.39371041e-01,  5.35658204e-04,  8.37848925e-01],
                [-3.67025535e-01,  6.82866602e-04,  9.28269288e-01],
                [-1.80585217e-01,  8.03832495e-04,  9.83020680e-01],
                [ 1.28037637e-02,  8.93915886e-04,  1.00000064e+00],
                [ 2.05700555e-01,  9.49637960e-04,  9.78541489e-01],
                [ 3.90694245e-01,  9.68871661e-04,  9.19483120e-01],
                [ 5.60662728e-01,  9.50871362e-04,  8.25093443e-01],
                [ 7.09095398e-01,  8.96327211e-04,  6.98988766e-01],
                [ 8.30277762e-01,  8.07337542e-04,  5.46022229e-01],
                [ 9.19545871e-01,  6.87319324e-04,  3.72072083e-01],
                [ 9.73480492e-01,  5.40898484e-04,  1.83833616e-01],
                [ 9.90010016e-01,  3.73684712e-04, -1.14790669e-02],
                [ 9.68484419e-01,  1.92107136e-04, -2.06350155e-01],
                [ 9.09745818e-01,  3.14724655e-06, -3.93293351e-01],
                [ 8.16050358e-01, -1.85921627e-04, -5.65110863e-01],
                [ 6.90987260e-01, -3.67858002e-04, -7.15222215e-01],
                [ 5.39369750e-01, -5.35657424e-04, -8.37847486e-01],
                [ 3.67034882e-01, -6.82861808e-04, -9.28267972e-01],
                [ 1.80583924e-01, -8.03831861e-04, -9.83019403e-01],
                [-1.28050572e-02, -8.93915252e-04, -9.99999361e-01],
                [-2.05701848e-01, -9.49637326e-04, -9.78540212e-01],
                [-3.90684898e-01, -9.68866866e-04, -9.19481804e-01],
                [-5.60664020e-01, -9.50870582e-04, -8.25092003e-01],
                [-7.09096691e-01, -8.96326578e-04, -6.98987489e-01],
                [-8.30279054e-01, -8.07336763e-04, -5.46020789e-01],
                [-9.19547466e-01, -6.87328503e-04, -3.72081713e-01],
                [-9.73481781e-01, -5.40897560e-04, -1.83832014e-01],
                [-9.56150771e-01, -2.49813591e-01,  1.10875248e-02],
                [-9.35370288e-01, -2.49638211e-01,  1.99312265e-01],
                [-8.78627992e-01, -2.49455687e-01,  3.79885634e-01],
                [-7.88123128e-01, -2.49273049e-01,  5.45860929e-01],
                [-6.67323606e-01, -2.49097317e-01,  6.90852657e-01],
                [-5.20876566e-01, -2.48935239e-01,  8.09297664e-01],
                [-3.54402256e-01, -2.48793044e-01,  8.96638715e-01],
                [-1.74304073e-01, -2.48676191e-01,  9.49529747e-01],
                [ 1.24888428e-02, -2.48589190e-01,  9.65919519e-01],
                [ 1.98817277e-01, -2.48535355e-01,  9.45203205e-01],
                [ 3.77496751e-01, -2.48516785e-01,  8.88151953e-01],
                [ 5.41685587e-01, -2.48534169e-01,  7.96976685e-01],
                [ 6.85056038e-01, -2.48586855e-01,  6.75171088e-01],
                [ 8.02107501e-01, -2.48672809e-01,  5.27421351e-01],
                [ 8.88335693e-01, -2.48788738e-01,  3.59396741e-01],
                [ 9.40437396e-01, -2.48930178e-01,  1.77561268e-01],
                [ 9.56392372e-01, -2.49091692e-01, -1.10894402e-02],
                [ 9.35611730e-01, -2.49267073e-01, -1.99314016e-01],
                [ 8.78869595e-01, -2.49449596e-01, -3.79887386e-01],
                [ 7.88364734e-01, -2.49632234e-01, -5.45862519e-01],
                [ 6.67564887e-01, -2.49807966e-01, -6.90854406e-01],
                [ 5.21118167e-01, -2.49970045e-01, -8.09299579e-01],
                [ 3.54643535e-01, -2.50112239e-01, -8.96640627e-01],
                [ 1.74556314e-01, -2.50229088e-01, -9.49531623e-01],
                [-1.22472396e-02, -2.50316093e-01, -9.65921272e-01],
                [-1.98565035e-01, -2.50369924e-01, -9.45205081e-01],
                [-3.77255473e-01, -2.50388498e-01, -8.88153865e-01],
                [-5.41443986e-01, -2.50371114e-01, -7.96978600e-01],
                [-6.84814757e-01, -2.50318429e-01, -6.75172837e-01],
                [-8.01865896e-01, -2.50232474e-01, -5.27422941e-01],
                [-8.88094089e-01, -2.50116545e-01, -3.59398493e-01],
                [-9.40195954e-01, -2.49975105e-01, -1.77563019e-01],
                [-8.57127314e-01, -4.98061065e-01,  9.93910754e-03],
                [-8.38488984e-01, -4.97903814e-01,  1.78703781e-01],
                [-7.87622951e-01, -4.97740179e-01,  3.40592839e-01],
                [-7.06479746e-01, -4.97576433e-01,  4.89399254e-01],
                [-5.98173147e-01, -4.97418871e-01,  6.19400421e-01],
                [-4.66867508e-01, -4.97273553e-01,  7.25595904e-01],
                [-3.17613399e-01, -4.97146067e-01,  8.03902569e-01],
                [-1.56150480e-01, -4.97041310e-01,  8.51315788e-01],
                [ 1.13305542e-02, -4.96963298e-01,  8.66017412e-01],
                [ 1.78385427e-01, -4.96915038e-01,  8.47436664e-01],
                [ 3.38586069e-01, -4.96898382e-01,  7.96293584e-01],
                [ 4.85791142e-01, -4.96913968e-01,  7.14549315e-01],
                [ 6.14338659e-01, -4.96961203e-01,  6.05340695e-01],
                [ 7.19284419e-01, -4.97038271e-01,  4.72866753e-01],
                [ 7.96593341e-01, -4.97142209e-01,  3.22223000e-01],
                [ 8.43310060e-01, -4.97269011e-01,  1.59202417e-01],
                [ 8.57621311e-01, -4.97413825e-01, -9.94432380e-03],
                [ 8.38983303e-01, -4.97571075e-01, -1.78709001e-01],
                [ 7.88106312e-01, -4.97734714e-01, -3.40597769e-01],
                [ 7.06963107e-01, -4.97898460e-01, -4.89404184e-01],
                [ 5.98656506e-01, -4.98056022e-01, -6.19405514e-01],
                [ 4.67350866e-01, -4.98201340e-01, -7.25600997e-01],
                [ 3.18096438e-01, -4.98328826e-01, -8.03907495e-01],
                [ 1.56633838e-01, -4.98433584e-01, -8.51320880e-01],
                [-1.08471937e-02, -4.98511595e-01, -8.66022342e-01],
                [-1.77902069e-01, -4.98559856e-01, -8.47441757e-01],
                [-3.38103031e-01, -4.98576512e-01, -7.96298510e-01],
                [-4.85307783e-01, -4.98560926e-01, -7.14554408e-01],
                [-6.13855301e-01, -4.98513691e-01, -6.05345788e-01],
                [-7.18801059e-01, -4.98436622e-01, -4.72871683e-01],
                [-7.96109980e-01, -4.98332685e-01, -3.22227930e-01],
                [-8.42815740e-01, -4.98205879e-01, -1.59207637e-01],
                [-6.93028653e-01, -6.98043554e-01,  8.03614468e-03],
                [-6.77952217e-01, -6.97916383e-01,  1.44516871e-01],
                [-6.36808301e-01, -6.97784046e-01,  2.75439149e-01],
                [-5.71187238e-01, -6.97651620e-01,  3.95783116e-01],
                [-4.83603372e-01, -6.97524204e-01,  5.00911881e-01],
                [-3.77419737e-01, -6.97406690e-01,  5.86788528e-01],
                [-2.56713747e-01, -6.97303590e-01,  6.50115910e-01],
                [-1.26135910e-01, -6.97218864e-01,  6.88467229e-01],
                [ 9.30681864e-03, -6.97155773e-01,  7.00360069e-01],
                [ 1.44404817e-01, -6.97116748e-01,  6.85330164e-01],
                [ 2.73961899e-01, -6.97103284e-01,  6.43962440e-01],
                [ 3.93010553e-01, -6.97115888e-01,  5.77854975e-01],
                [ 4.96963788e-01, -6.97154085e-01,  4.89541678e-01],
                [ 5.81829503e-01, -6.97216409e-01,  3.82413267e-01],
                [ 6.44360957e-01, -6.97300462e-01,  2.60583303e-01],
                [ 6.82129428e-01, -6.97403014e-01,  1.28745994e-01],
                [ 6.93706796e-01, -6.97520124e-01, -8.04379771e-03],
                [ 6.78630360e-01, -6.97647294e-01, -1.44524524e-01],
                [ 6.37497408e-01, -6.97779628e-01, -2.75446766e-01],
                [ 5.71865062e-01, -6.97912057e-01, -3.95790602e-01],
                [ 4.84281516e-01, -6.98039473e-01, -5.00919534e-01],
                [ 3.78097883e-01, -6.98156987e-01, -5.86796019e-01],
                [ 2.57391894e-01, -6.98260087e-01, -6.50123237e-01],
                [ 1.26814054e-01, -6.98344813e-01, -6.88474882e-01],
                [-8.62867490e-03, -6.98407905e-01, -7.00367722e-01],
                [-1.43726674e-01, -6.98446930e-01, -6.85337817e-01],
                [-2.73283751e-01, -6.98460393e-01, -6.43969768e-01],
                [-3.92332407e-01, -6.98447790e-01, -5.77862466e-01],
                [-4.96285644e-01, -6.98409593e-01, -4.89549331e-01],
                [-5.81151680e-01, -6.98347269e-01, -3.82420754e-01],
                [-6.43671850e-01, -6.98263211e-01, -2.60590920e-01],
                [-6.81451284e-01, -6.98160664e-01, -1.28753647e-01],
                [-1.69002248e-01, -8.38610973e-01,  1.95967097e-03],
                [-1.65330726e-01, -8.38579977e-01,  3.52259059e-02],
                [-1.55304038e-01, -8.38547719e-01,  6.71398215e-02],
                [-1.39305828e-01, -8.38515442e-01,  9.64712056e-02],
                [-1.17956727e-01, -8.38484389e-01,  1.22090298e-01],
                [-9.20694737e-02, -8.38455743e-01,  1.43023290e-01],
                [-6.26500693e-02, -8.38430610e-01,  1.58462430e-01],
                [-3.08198566e-02, -8.38409960e-01,  1.67808438e-01],
                [ 2.18233306e-03, -8.38394588e-01,  1.70704075e-01],
                [ 3.51115424e-02, -8.38385073e-01,  1.67043928e-01],
                [ 6.66926775e-02, -8.38381789e-01,  1.56962631e-01],
                [ 9.57080276e-02, -8.38384865e-01,  1.40845909e-01],
                [ 1.21051606e-01, -8.38394174e-01,  1.19318868e-01],
                [ 1.41738390e-01, -8.38409360e-01,  9.32123469e-02],
                [ 1.56980820e-01, -8.38429846e-01,  6.35187109e-02],
                [ 1.66187374e-01, -8.38454844e-01,  3.13817755e-02],
                [ 1.69006023e-01, -8.38483390e-01, -1.95971648e-03],
                [ 1.65334501e-01, -8.38514386e-01, -3.52259515e-02],
                [ 1.55307814e-01, -8.38546644e-01, -6.71398670e-02],
                [ 1.39309606e-01, -8.38578921e-01, -9.64710883e-02],
                [ 1.17960505e-01, -8.38609974e-01, -1.22090181e-01],
                [ 9.20732493e-02, -8.38638620e-01, -1.43023336e-01],
                [ 6.26538470e-02, -8.38663752e-01, -1.58462313e-01],
                [ 3.08239567e-02, -8.38684403e-01, -1.67808324e-01],
                [-2.18919394e-03, -8.38699778e-01, -1.70703835e-01],
                [-3.51074423e-02, -8.38709289e-01, -1.67043814e-01],
                [-6.66888998e-02, -8.38712574e-01, -1.56962514e-01],
                [-9.57042520e-02, -8.38709498e-01, -1.40845955e-01],
                [-1.21047828e-01, -8.38700188e-01, -1.19318751e-01],
                [-1.41734612e-01, -8.38685003e-01, -9.32122296e-02],
                [-1.56977044e-01, -8.38664517e-01, -6.35187564e-02],
                [-1.66183598e-01, -8.38639519e-01, -3.13818210e-02],
                [-1.05883473e-01, -8.38230144e-01,  1.22777515e-03],
                [-1.03582673e-01, -8.38210720e-01,  2.20737344e-02],
                [-9.73005051e-02, -8.38190513e-01,  4.20648591e-02],
                [-8.72740437e-02, -8.38170292e-01,  6.04388708e-02],
                [-7.39018181e-02, -8.38150838e-01,  7.64900783e-02],
                [-5.76894147e-02, -8.38132886e-01,  8.96127130e-02],
                [-3.92491280e-02, -8.38117144e-01,  9.92778023e-02],
                [-1.93109263e-02, -8.38104207e-01,  1.05133606e-01],
                [ 1.36580348e-03, -8.38094576e-01,  1.06948251e-01],
                [ 2.20005688e-02, -8.38088614e-01,  1.04654577e-01],
                [ 4.17832352e-02, -8.38086558e-01,  9.83381885e-02],
                [ 5.99702497e-02, -8.38088475e-01,  8.82483860e-02],
                [ 7.58421566e-02, -8.38094316e-01,  7.47537165e-02],
                [ 8.87990981e-02, -8.38103832e-01,  5.83972082e-02],
                [ 9.83521157e-02, -8.38116663e-01,  3.97961618e-02],
                [ 1.04120545e-01, -8.38132322e-01,  1.96653041e-02],
                [ 1.05886901e-01, -8.38150210e-01, -1.22781609e-03],
                [ 1.03586101e-01, -8.38169633e-01, -2.20737754e-02],
                [ 9.73039331e-02, -8.38189840e-01, -4.20649000e-02],
                [ 8.72774717e-02, -8.38210062e-01, -6.04389118e-02],
                [ 7.39055684e-02, -8.38229516e-01, -7.64901230e-02],
                [ 5.76928448e-02, -8.38247467e-01, -8.96125912e-02],
                [ 3.92528804e-02, -8.38263210e-01, -9.92776842e-02],
                [ 1.93143564e-02, -8.38276146e-01, -1.05133484e-01],
                [-1.37301198e-03, -8.38285781e-01, -1.06948006e-01],
                [-2.19971388e-02, -8.38291740e-01, -1.04654455e-01],
                [-4.17794827e-02, -8.38293796e-01, -9.83380704e-02],
                [-5.99668197e-02, -8.38291879e-01, -8.82482642e-02],
                [-7.58384063e-02, -8.38286037e-01, -7.47537611e-02],
                [-8.87956701e-02, -8.38276521e-01, -5.83972491e-02],
                [-9.83486878e-02, -8.38263690e-01, -3.97962028e-02],
                [-1.04117117e-01, -8.38248032e-01, -1.96653450e-02],
                [-3.49777704e-01, -8.45825423e-01,  4.05585410e-03],
                [-3.42177397e-01, -8.45761275e-01,  7.29022432e-02],
                [-3.21424928e-01, -8.45694514e-01,  1.38951262e-01],
                [-2.88320804e-01, -8.45627705e-01,  1.99666335e-01],
                [-2.44138671e-01, -8.45563427e-01,  2.52701363e-01],
                [-1.90560571e-01, -8.45504141e-01,  2.96022099e-01],
                [-1.29673735e-01, -8.45452123e-01,  3.27980041e-01],
                [-6.37982620e-02, -8.45409383e-01,  3.47323791e-01],
                [ 4.52407382e-03, -8.45377562e-01,  3.53317794e-01],
                [ 7.26836089e-02, -8.45357867e-01,  3.45741210e-01],
                [ 1.38043903e-01, -8.45351071e-01,  3.24875711e-01],
                [ 1.98094378e-01, -8.45357442e-01,  2.91515436e-01],
                [ 2.50536704e-01, -8.45376709e-01,  2.46965337e-01],
                [ 2.93358395e-01, -8.45408147e-01,  1.92921453e-01],
                [ 3.24898402e-01, -8.45450556e-01,  1.31456796e-01],
                [ 3.43953523e-01, -8.45502292e-01,  6.49461866e-02],
                [ 3.49788438e-01, -8.45561369e-01, -4.05599107e-03],
                [ 3.42188457e-01, -8.45625517e-01, -7.29020583e-02],
                [ 3.21435987e-01, -8.45692278e-01, -1.38951240e-01],
                [ 2.88331542e-01, -8.45759087e-01, -1.99666147e-01],
                [ 2.44138766e-01, -8.45823369e-01, -2.52701377e-01],
                [ 1.90571307e-01, -8.45882651e-01, -2.96022073e-01],
                [ 1.29684471e-01, -8.45934669e-01, -3.27980015e-01],
                [ 6.38093204e-02, -8.45977409e-01, -3.47323769e-01],
                [-4.52397844e-03, -8.46009234e-01, -3.53317807e-01],
                [-7.26725505e-02, -8.46028925e-01, -3.45741188e-01],
                [-1.38033167e-01, -8.46035721e-01, -3.24875685e-01],
                [-1.98083642e-01, -8.46029350e-01, -2.91515410e-01],
                [-2.50536608e-01, -8.46010087e-01, -2.46965350e-01],
                [-2.93347657e-01, -8.45978645e-01, -1.92921264e-01],
                [-3.24887344e-01, -8.45936236e-01, -1.31456774e-01],
                [-3.43942462e-01, -8.45884500e-01, -6.49460017e-02],
                [-4.27320140e-01, -8.37562388e-01,  4.95500655e-03],
                [-4.18031483e-01, -8.37484012e-01,  8.90699861e-02],
                [-3.92677582e-01, -8.37402457e-01,  1.69753259e-01],
                [-3.52238749e-01, -8.37320844e-01,  2.43922863e-01],
                [-2.98255814e-01, -8.37242316e-01,  3.08712426e-01],
                [-2.32816000e-01, -8.37169888e-01,  3.61643283e-01],
                [-1.58422923e-01, -8.37106341e-01,  4.00678989e-01],
                [-7.79416390e-02, -8.37054124e-01,  4.24312290e-01],
                [ 5.52288798e-03, -8.37015247e-01,  4.31638619e-01],
                [ 8.87856817e-02, -8.36991192e-01,  4.22378997e-01],
                [ 1.68638262e-01, -8.36982890e-01,  3.96886539e-01],
                [ 2.42009741e-01, -8.36990663e-01,  3.56137423e-01],
                [ 3.06074508e-01, -8.37014209e-01,  3.01704891e-01],
                [ 3.58382477e-01, -8.37052616e-01,  2.35682829e-01],
                [ 3.96910190e-01, -8.37104424e-01,  1.60597564e-01],
                [ 4.20190666e-01, -8.37167621e-01,  7.93503501e-02],
                [ 4.27322800e-01, -8.37239799e-01, -4.95503739e-03],
                [ 4.18034142e-01, -8.37318175e-01, -8.90700170e-02],
                [ 3.92680246e-01, -8.37399729e-01, -1.69752964e-01],
                [ 3.52241408e-01, -8.37481343e-01, -2.43922894e-01],
                [ 2.98258474e-01, -8.37559870e-01, -3.08712457e-01],
                [ 2.32818984e-01, -8.37632298e-01, -3.61643155e-01],
                [ 1.58425905e-01, -8.37695846e-01, -4.00679023e-01],
                [ 7.79443007e-02, -8.37748063e-01, -4.24312158e-01],
                [-5.53086690e-03, -8.37786944e-01, -4.31638526e-01],
                [-8.87830200e-02, -8.37810995e-01, -4.22378865e-01],
                [-1.68635279e-01, -8.37819297e-01, -3.96886573e-01],
                [-2.42006757e-01, -8.37811524e-01, -3.56137295e-01],
                [-3.06071848e-01, -8.37787978e-01, -3.01704922e-01],
                [-3.58379817e-01, -8.37749571e-01, -2.35682859e-01],
                [-3.96907526e-01, -8.37697763e-01, -1.60597270e-01],
                [-4.20188006e-01, -8.37634566e-01, -7.93503809e-02],
                [-2.59953294e-01, -8.40555500e-01,  5.53927663e-02],
                [-2.44186043e-01, -8.40504785e-01,  1.05566247e-01],
                [ 1.44774423e-01, -8.40647725e-01, -2.24895532e-01],
                [ 1.85474621e-01, -8.40602684e-01, -1.91982292e-01],
                [-4.84681474e-02, -8.40288174e-01,  2.63863266e-01],
                [ 3.43447113e-03, -8.40263998e-01,  2.68419254e-01],
                [-1.04860594e-01, -8.40764002e-01, -2.46807595e-01],
                [-1.50494851e-01, -8.40759175e-01, -2.21471726e-01],
                [ 2.22861330e-01, -8.40287238e-01,  1.46562231e-01],
                [ 2.46822250e-01, -8.40319451e-01,  9.98727423e-02],
                [-2.65729737e-01, -8.40604243e-01,  3.08127670e-03],
                [ 2.19042435e-01, -8.40553847e-01, -1.51686185e-01],
                [-9.85099428e-02, -8.40320644e-01,  2.49166107e-01],
                [-5.52099790e-02, -8.40758843e-01, -2.62660904e-01],
                [ 1.90335263e-01, -8.40263348e-01,  1.87624570e-01],
                [ 2.44191724e-01, -8.40503096e-01, -1.05566318e-01],
                [-1.44779378e-01, -8.40360161e-01,  2.24895748e-01],
                [-3.43942878e-03, -8.40743887e-01, -2.68419201e-01],
                [ 1.50489895e-01, -8.40248710e-01,  2.21471942e-01],
                [-2.46816569e-01, -8.40688430e-01, -9.98728129e-02],
                [-2.61294441e-01, -8.40649130e-01, -4.93482979e-02],
                [ 2.59958979e-01, -8.40452380e-01, -5.53925113e-02],
                [-1.85468940e-01, -8.40405197e-01,  1.91982222e-01],
                [ 4.84738304e-02, -8.40719707e-01, -2.63863173e-01],
                [ 1.04866279e-01, -8.40243878e-01,  2.46807850e-01],
                [-2.22855325e-01, -8.40720643e-01, -1.46562143e-01],
                [ 2.65735418e-01, -8.40403639e-01, -3.08134725e-03],
                [-2.19036429e-01, -8.40454034e-01,  1.51686273e-01],
                [ 9.85156279e-02, -8.40687237e-01, -2.49165852e-01],
                [ 5.52156620e-02, -8.40249038e-01,  2.62660996e-01],
                [-1.90329582e-01, -8.40744533e-01, -1.87624641e-01],
                [ 2.61300126e-01, -8.40358751e-01,  4.93485530e-02],
                [-9.56393666e-01,  2.49091693e-01,  1.10907172e-02],
                [-9.35613182e-01,  2.49267073e-01,  1.99315458e-01],
                [-8.78870887e-01,  2.49449597e-01,  3.79888826e-01],
                [-7.88366023e-01,  2.49632235e-01,  5.45864121e-01],
                [-6.67566500e-01,  2.49807967e-01,  6.90855849e-01],
                [-5.21119460e-01,  2.49970045e-01,  8.09300856e-01],
                [-3.54645151e-01,  2.50112240e-01,  8.96641907e-01],
                [-1.74546967e-01,  2.50229093e-01,  9.49532940e-01],
                [ 1.22459482e-02,  2.50316094e-01,  9.65922712e-01],
                [ 1.98574382e-01,  2.50369929e-01,  9.45206397e-01],
                [ 3.77253857e-01,  2.50388499e-01,  8.88155145e-01],
                [ 5.41442693e-01,  2.50371115e-01,  7.96979877e-01],
                [ 6.84813143e-01,  2.50318429e-01,  6.75174281e-01],
                [ 8.01864606e-01,  2.50232475e-01,  5.27424543e-01],
                [ 8.88092798e-01,  2.50116546e-01,  3.59399933e-01],
                [ 9.40194501e-01,  2.49975106e-01,  1.77564460e-01],
                [ 9.56149478e-01,  2.49813592e-01, -1.10862478e-02],
                [ 9.35368835e-01,  2.49638211e-01, -1.99310824e-01],
                [ 8.78626701e-01,  2.49455688e-01, -3.79884194e-01],
                [ 7.88121839e-01,  2.49273050e-01, -5.45859326e-01],
                [ 6.67321992e-01,  2.49097318e-01, -6.90851213e-01],
                [ 5.20875272e-01,  2.48935239e-01, -8.09296387e-01],
                [ 3.54400640e-01,  2.48793045e-01, -8.96637434e-01],
                [ 1.74313420e-01,  2.48676196e-01, -9.49528431e-01],
                [-1.24901342e-02,  2.48589191e-01, -9.65918079e-01],
                [-1.98807930e-01,  2.48535360e-01, -9.45201888e-01],
                [-3.77498367e-01,  2.48516786e-01, -8.88150672e-01],
                [-5.41686881e-01,  2.48534170e-01, -7.96975408e-01],
                [-6.85057651e-01,  2.48586855e-01, -6.75169645e-01],
                [-8.02108790e-01,  2.48672810e-01, -5.27419748e-01],
                [-8.88336984e-01,  2.48788739e-01, -3.59395301e-01],
                [-9.40438848e-01,  2.48930179e-01, -1.77559826e-01],
                [-8.57611966e-01,  4.97413990e-01,  9.94547746e-03],
                [-8.38973636e-01,  4.97571241e-01,  1.78710150e-01],
                [-7.88107603e-01,  4.97734876e-01,  3.40599209e-01],
                [-7.06964399e-01,  4.97898622e-01,  4.89405624e-01],
                [-5.98657799e-01,  4.98056184e-01,  6.19406791e-01],
                [-4.67352160e-01,  4.98201502e-01,  7.25602274e-01],
                [-3.18098051e-01,  4.98328988e-01,  8.03908939e-01],
                [-1.56635132e-01,  4.98433745e-01,  8.51322157e-01],
                [ 1.08459021e-02,  4.98511757e-01,  8.66023782e-01],
                [ 1.77900775e-01,  4.98560018e-01,  8.47443034e-01],
                [ 3.38101417e-01,  4.98576674e-01,  7.96299954e-01],
                [ 4.85306490e-01,  4.98561088e-01,  7.14555685e-01],
                [ 6.13854007e-01,  4.98513853e-01,  6.05347065e-01],
                [ 7.18799767e-01,  4.98436784e-01,  4.72873123e-01],
                [ 7.96108689e-01,  4.98332847e-01,  3.22229370e-01],
                [ 8.42825408e-01,  4.98206044e-01,  1.59208787e-01],
                [ 8.57136659e-01,  4.98061231e-01, -9.93795388e-03],
                [ 8.38498651e-01,  4.97903980e-01, -1.78702631e-01],
                [ 7.87621660e-01,  4.97740341e-01, -3.40591399e-01],
                [ 7.06478455e-01,  4.97576595e-01, -4.89397814e-01],
                [ 5.98171854e-01,  4.97419033e-01, -6.19399144e-01],
                [ 4.66866214e-01,  4.97273715e-01, -7.25594627e-01],
                [ 3.17611785e-01,  4.97146229e-01, -8.03901125e-01],
                [ 1.56149186e-01,  4.97041472e-01, -8.51314511e-01],
                [-1.13318457e-02,  4.96963460e-01, -8.66015972e-01],
                [-1.78386721e-01,  4.96915200e-01, -8.47435387e-01],
                [-3.38587683e-01,  4.96898543e-01, -7.96292140e-01],
                [-4.85792435e-01,  4.96914129e-01, -7.14548038e-01],
                [-6.14339953e-01,  4.96961364e-01, -6.05339418e-01],
                [-7.19285711e-01,  4.97038433e-01, -4.72865313e-01],
                [-7.96594632e-01,  4.97142371e-01, -3.22221560e-01],
                [-8.43300392e-01,  4.97269177e-01, -1.59201267e-01],
                [-6.82469184e-01,  6.97481172e-01,  7.89293285e-03],
                [-6.67291443e-01,  6.97184772e-01,  1.42121370e-01],
                [-6.26254589e-01,  6.96568824e-01,  2.70596736e-01],
                [-5.61033017e-01,  6.95715149e-01,  3.88410225e-01],
                [-4.74631582e-01,  6.94780027e-01,  4.90722198e-01],
                [-3.69731536e-01,  6.93867983e-01,  5.74318647e-01],
                [-2.51133999e-01,  6.92940859e-01,  6.35157187e-01],
                [-1.23365629e-01,  6.92093496e-01,  6.72076817e-01],
                [ 8.18273991e-03,  6.91678603e-01,  6.83140683e-01],
                [ 1.39926918e-01,  6.91218969e-01,  6.68073132e-01],
                [ 2.66236455e-01,  6.91491365e-01,  6.27442305e-01],
                [ 3.82445206e-01,  6.91793062e-01,  5.63465814e-01],
                [ 4.84827519e-01,  6.92264471e-01,  4.77509781e-01],
                [ 5.67589345e-01,  6.92582436e-01,  3.73389014e-01],
                [ 6.29217050e-01,  6.93138481e-01,  2.54530957e-01],
                [ 6.66444155e-01,  6.93460295e-01,  1.26032956e-01],
                [ 6.78133831e-01,  6.93767570e-01, -7.86217242e-03],
                [ 6.63019238e-01,  6.93221191e-01, -1.41446492e-01],
                [ 6.22512994e-01,  6.92670450e-01, -2.69042971e-01],
                [ 5.57860224e-01,  6.91903216e-01, -3.86436739e-01],
                [ 4.72456956e-01,  6.91400843e-01, -4.88607542e-01],
                [ 3.67904133e-01,  6.90777904e-01, -5.72164214e-01],
                [ 2.50091768e-01,  6.90364255e-01, -6.33426942e-01],
                [ 1.22779379e-01,  6.90021846e-01, -6.71116887e-01],
                [-9.31148829e-03,  6.90457277e-01, -6.83125128e-01],
                [-1.40537646e-01,  6.90883870e-01, -6.69025323e-01],
                [-2.67322617e-01,  6.91810682e-01, -6.29142936e-01],
                [-3.84338272e-01,  6.92849003e-01, -5.65583406e-01],
                [-4.87055578e-01,  6.93901875e-01, -4.79568610e-01],
                [-5.70811664e-01,  6.95032471e-01, -3.75283405e-01],
                [-6.32997257e-01,  6.96098098e-01, -2.55992723e-01],
                [-6.70732311e-01,  6.96944555e-01, -1.26603790e-01],
                [-2.80870824e-01,  9.29862110e-01,  2.38404916e-03],
                [-2.74034171e-01,  9.29602849e-01,  6.06060990e-02],
                [-2.56579065e-01,  9.29538339e-01,  1.14169900e-01],
                [-2.30414792e-01,  9.29060338e-01,  1.60922685e-01],
                [-1.93242907e-01,  9.29156859e-01,  2.04717654e-01],
                [-1.51341138e-01,  9.28532212e-01,  2.37671512e-01],
                [-1.01830581e-01,  9.28357786e-01,  2.63248378e-01],
                [-4.97857339e-02,  9.27947943e-01,  2.78064307e-01],
                [ 6.05065529e-03,  9.28005723e-01,  2.82279939e-01],
                [ 5.91002769e-02,  9.27609766e-01,  2.75851049e-01],
                [ 1.11822464e-01,  9.27679484e-01,  2.58246594e-01],
                [ 1.58115470e-01,  9.27576754e-01,  2.31952258e-01],
                [ 2.01380945e-01,  9.27895646e-01,  1.94852374e-01],
                [ 2.33915755e-01,  9.27557349e-01,  1.52773806e-01],
                [ 2.58137896e-01,  9.27946190e-01,  1.05349155e-01],
                [ 2.73903367e-01,  9.27838135e-01,  4.97717335e-02],
                [ 2.78515723e-01,  9.28031384e-01, -2.34300530e-03],
                [ 2.72031072e-01,  9.27752019e-01, -5.84271262e-02],
                [ 2.55285690e-01,  9.27741535e-01, -1.11485556e-01],
                [ 2.29923781e-01,  9.27290190e-01, -1.58160363e-01],
                [ 1.96628000e-01,  9.27511165e-01, -1.99158864e-01],
                [ 1.51660003e-01,  9.27201557e-01, -2.35869410e-01],
                [ 1.05469558e-01,  9.27150761e-01, -2.60719748e-01],
                [ 5.21172382e-02,  9.27104704e-01, -2.77116033e-01],
                [-1.02183356e-03,  9.27349430e-01, -2.82739762e-01],
                [-5.75915257e-02,  9.27516744e-01, -2.76630749e-01],
                [-1.08637596e-01,  9.27900282e-01, -2.60761421e-01],
                [-1.57648998e-01,  9.28164571e-01, -2.33856501e-01],
                [-1.98236732e-01,  9.28708350e-01, -2.00503211e-01],
                [-2.34710909e-01,  9.28810077e-01, -1.55154874e-01],
                [-2.59297791e-01,  9.29339516e-01, -1.08305381e-01],
                [-2.75418303e-01,  9.29521947e-01, -5.42648076e-02],
                [-4.67572058e-01,  8.50985950e-01,  1.00825071e-01],
                [-4.38772629e-01,  8.51023491e-01,  1.91205308e-01],
                [ 3.32240202e-01,  8.46901615e-01, -3.42708937e-01],
                [ 2.59299478e-01,  8.46615363e-01, -4.01836527e-01],
                [-8.63865636e-02,  8.47507294e-01,  4.72669749e-01],
                [ 6.82081142e-03,  8.47485610e-01,  4.80473566e-01],
                [-1.87235807e-01,  8.47313882e-01, -4.42862574e-01],
                [-2.69339265e-01,  8.48219318e-01, -3.97946880e-01],
                [ 3.98811401e-01,  8.47940393e-01,  2.61628445e-01],
                [ 4.41845301e-01,  8.48412173e-01,  1.77693605e-01],
                [-4.78383978e-01,  8.51352299e-01,  6.77230507e-03],
                [ 3.91983385e-01,  8.47464446e-01, -2.70795596e-01],
                [-1.75840676e-01,  8.48109411e-01,  4.47075344e-01],
                [-9.84636038e-02,  8.46675114e-01, -4.70523611e-01],
                [ 3.40916662e-01,  8.47507345e-01,  3.34906023e-01],
                [ 4.37164300e-01,  8.48085378e-01, -1.87883654e-01],
                [-2.59133215e-01,  8.48828252e-01,  4.04208593e-01],
                [-5.48371925e-03,  8.46637387e-01, -4.80486369e-01],
                [ 2.69511557e-01,  8.47328300e-01,  3.95707380e-01],
                [-4.43788593e-01,  8.50485179e-01, -1.81099916e-01],
                [-4.70014969e-01,  8.50815403e-01, -8.99616114e-02],
                [ 4.65079293e-01,  8.48013750e-01, -9.81381749e-02],
                [-3.32458118e-01,  8.49526111e-01,  3.45533597e-01],
                [ 8.70628534e-02,  8.46129421e-01, -4.71931846e-01],
                [ 1.87946340e-01,  8.47099340e-01,  4.41217879e-01],
                [-3.99956908e-01,  8.49768531e-01, -2.64442961e-01],
                [ 4.75348680e-01,  8.48509979e-01, -6.71274554e-03],
                [-3.93077553e-01,  8.50238744e-01,  2.73652075e-01],
                [ 1.76593181e-01,  8.46306741e-01, -4.45442210e-01],
                [ 9.91208605e-02,  8.46971228e-01,  4.69775484e-01],
                [-3.41206769e-01,  8.48915340e-01, -3.37719386e-01],
                [ 4.67454073e-01,  8.48179541e-01,  8.73276523e-02],
                [-2.78458428e-02,  9.61180335e-01, -1.22933557e-01],
                [-4.85067998e-02,  9.61286669e-01, -1.15907582e-01],
                [-6.83837708e-02,  9.61211307e-01, -1.06836295e-01],
                [-8.79935587e-02,  9.62008353e-01, -8.95065286e-02],
                [-1.04922692e-01,  9.61759102e-01, -7.07323440e-02],
                [-1.16271845e-01,  9.61830432e-01, -4.62530784e-02],
                [-1.22699899e-01,  9.61814217e-01, -2.52622619e-02],
                [-1.22189021e-01,  9.61893548e-01,  2.73288175e-02],
                [-1.13756939e-01,  9.61799985e-01,  5.21470241e-02],
                [-1.06401433e-01,  9.61827797e-01,  6.80823599e-02],
                [-8.36269212e-02,  9.61934941e-01,  9.34992857e-02],
                [-6.85508229e-02,  9.61649702e-01,  1.06580056e-01],
                [-4.43831672e-02,  9.61419971e-01,  1.17424467e-01],
                [-2.38223120e-02,  9.61390355e-01,  1.23710116e-01],
                [-1.25052218e-01,  9.62247846e-01,  1.42958306e-03],
                [ 2.59349232e-02,  9.61149434e-01,  1.22947515e-01],
                [ 5.08473275e-02,  9.61010836e-01,  1.14200353e-01],
                [ 6.66130733e-02,  9.61031954e-01,  1.06793913e-01],
                [ 9.11859430e-02,  9.61324144e-01,  8.42378602e-02],
                [ 1.04432000e-01,  9.61055885e-01,  6.84678095e-02],
                [ 1.14998645e-01,  9.60973791e-01,  4.45441121e-02],
                [ 1.20809955e-01,  9.60937299e-01,  2.52432463e-02],
                [ 3.08806969e-03,  9.61575578e-01,  1.25693158e-01],
                [ 1.20300172e-01,  9.60912016e-01, -2.72602373e-02],
                [ 1.13533487e-01,  9.60912612e-01, -4.79231623e-02],
                [ 1.04502346e-01,  9.60729200e-01, -6.79918404e-02],
                [ 8.71058554e-02,  9.61363863e-01, -8.82256913e-02],
                [ 6.85160793e-02,  9.60876646e-01, -1.05352866e-01],
                [ 4.47115639e-02,  9.60976336e-01, -1.16573254e-01],
                [ 2.39618436e-02,  9.60865038e-01, -1.23261048e-01],
                [-1.30864610e-04,  9.61264339e-01, -1.25702753e-01],
                [ 1.23151256e-01,  9.61281956e-01, -1.44847033e-03],
                [ 1.47801402e-03,  9.61765898e-01, -3.76033347e-05],
            ],
            dtype=np.float32,
        )
        self.mean_r = np.asarray(
                [
                    [-9.90011310e-01, -3.73684078e-04, -1.14803439e-02],
                    [-9.68485708e-01, -1.92106212e-04, -2.06351758e-01],
                    [-9.09747412e-01, -3.15642525e-06, -3.93283721e-01],
                    [-8.16051650e-01,  1.85922406e-04, -5.65112303e-01],
                    [-6.90988553e-01,  3.67858636e-04, -7.15223492e-01],
                    [-5.39371041e-01,  5.35658204e-04, -8.37848925e-01],
                    [-3.67025535e-01,  6.82866602e-04, -9.28269288e-01],
                    [-1.80585217e-01,  8.03832495e-04, -9.83020680e-01],
                    [ 1.28037637e-02,  8.93915886e-04, -1.00000064e+00],
                    [ 2.05700555e-01,  9.49637960e-04, -9.78541489e-01],
                    [ 3.90694245e-01,  9.68871661e-04, -9.19483120e-01],
                    [ 5.60662728e-01,  9.50871362e-04, -8.25093443e-01],
                    [ 7.09095398e-01,  8.96327211e-04, -6.98988766e-01],
                    [ 8.30277762e-01,  8.07337542e-04, -5.46022229e-01],
                    [ 9.19545871e-01,  6.87319324e-04, -3.72072083e-01],
                    [ 9.73480492e-01,  5.40898484e-04, -1.83833616e-01],
                    [ 9.90010016e-01,  3.73684712e-04,  1.14790669e-02],
                    [ 9.68484419e-01,  1.92107136e-04,  2.06350155e-01],
                    [ 9.09745818e-01,  3.14724655e-06,  3.93293351e-01],
                    [ 8.16050358e-01, -1.85921627e-04,  5.65110863e-01],
                    [ 6.90987260e-01, -3.67858002e-04,  7.15222215e-01],
                    [ 5.39369750e-01, -5.35657424e-04,  8.37847486e-01],
                    [ 3.67034882e-01, -6.82861808e-04,  9.28267972e-01],
                    [ 1.80583924e-01, -8.03831861e-04,  9.83019403e-01],
                    [-1.28050572e-02, -8.93915252e-04,  9.99999361e-01],
                    [-2.05701848e-01, -9.49637326e-04,  9.78540212e-01],
                    [-3.90684898e-01, -9.68866866e-04,  9.19481804e-01],
                    [-5.60664020e-01, -9.50870582e-04,  8.25092003e-01],
                    [-7.09096691e-01, -8.96326578e-04,  6.98987489e-01],
                    [-8.30279054e-01, -8.07336763e-04,  5.46020789e-01],
                    [-9.19547466e-01, -6.87328503e-04,  3.72081713e-01],
                    [-9.73481781e-01, -5.40897560e-04,  1.83832014e-01],
                    [-9.56150771e-01, -2.49813591e-01, -1.10875248e-02],
                    [-9.35370288e-01, -2.49638211e-01, -1.99312265e-01],
                    [-8.78627992e-01, -2.49455687e-01, -3.79885634e-01],
                    [-7.88123128e-01, -2.49273049e-01, -5.45860929e-01],
                    [-6.67323606e-01, -2.49097317e-01, -6.90852657e-01],
                    [-5.20876566e-01, -2.48935239e-01, -8.09297664e-01],
                    [-3.54402256e-01, -2.48793044e-01, -8.96638715e-01],
                    [-1.74304073e-01, -2.48676191e-01, -9.49529747e-01],
                    [ 1.24888428e-02, -2.48589190e-01, -9.65919519e-01],
                    [ 1.98817277e-01, -2.48535355e-01, -9.45203205e-01],
                    [ 3.77496751e-01, -2.48516785e-01, -8.88151953e-01],
                    [ 5.41685587e-01, -2.48534169e-01, -7.96976685e-01],
                    [ 6.85056038e-01, -2.48586855e-01, -6.75171088e-01],
                    [ 8.02107501e-01, -2.48672809e-01, -5.27421351e-01],
                    [ 8.88335693e-01, -2.48788738e-01, -3.59396741e-01],
                    [ 9.40437396e-01, -2.48930178e-01, -1.77561268e-01],
                    [ 9.56392372e-01, -2.49091692e-01,  1.10894402e-02],
                    [ 9.35611730e-01, -2.49267073e-01,  1.99314016e-01],
                    [ 8.78869595e-01, -2.49449596e-01,  3.79887386e-01],
                    [ 7.88364734e-01, -2.49632234e-01,  5.45862519e-01],
                    [ 6.67564887e-01, -2.49807966e-01,  6.90854406e-01],
                    [ 5.21118167e-01, -2.49970045e-01,  8.09299579e-01],
                    [ 3.54643535e-01, -2.50112239e-01,  8.96640627e-01],
                    [ 1.74556314e-01, -2.50229088e-01,  9.49531623e-01],
                    [-1.22472396e-02, -2.50316093e-01,  9.65921272e-01],
                    [-1.98565035e-01, -2.50369924e-01,  9.45205081e-01],
                    [-3.77255473e-01, -2.50388498e-01,  8.88153865e-01],
                    [-5.41443986e-01, -2.50371114e-01,  7.96978600e-01],
                    [-6.84814757e-01, -2.50318429e-01,  6.75172837e-01],
                    [-8.01865896e-01, -2.50232474e-01,  5.27422941e-01],
                    [-8.88094089e-01, -2.50116545e-01,  3.59398493e-01],
                    [-9.40195954e-01, -2.49975105e-01,  1.77563019e-01],
                    [-8.57127314e-01, -4.98061065e-01, -9.93910754e-03],
                    [-8.38488984e-01, -4.97903814e-01, -1.78703781e-01],
                    [-7.87622951e-01, -4.97740179e-01, -3.40592839e-01],
                    [-7.06479746e-01, -4.97576433e-01, -4.89399254e-01],
                    [-5.98173147e-01, -4.97418871e-01, -6.19400421e-01],
                    [-4.66867508e-01, -4.97273553e-01, -7.25595904e-01],
                    [-3.17613399e-01, -4.97146067e-01, -8.03902569e-01],
                    [-1.56150480e-01, -4.97041310e-01, -8.51315788e-01],
                    [ 1.13305542e-02, -4.96963298e-01, -8.66017412e-01],
                    [ 1.78385427e-01, -4.96915038e-01, -8.47436664e-01],
                    [ 3.38586069e-01, -4.96898382e-01, -7.96293584e-01],
                    [ 4.85791142e-01, -4.96913968e-01, -7.14549315e-01],
                    [ 6.14338659e-01, -4.96961203e-01, -6.05340695e-01],
                    [ 7.19284419e-01, -4.97038271e-01, -4.72866753e-01],
                    [ 7.96593341e-01, -4.97142209e-01, -3.22223000e-01],
                    [ 8.43310060e-01, -4.97269011e-01, -1.59202417e-01],
                    [ 8.57621311e-01, -4.97413825e-01,  9.94432380e-03],
                    [ 8.38983303e-01, -4.97571075e-01,  1.78709001e-01],
                    [ 7.88106312e-01, -4.97734714e-01,  3.40597769e-01],
                    [ 7.06963107e-01, -4.97898460e-01,  4.89404184e-01],
                    [ 5.98656506e-01, -4.98056022e-01,  6.19405514e-01],
                    [ 4.67350866e-01, -4.98201340e-01,  7.25600997e-01],
                    [ 3.18096438e-01, -4.98328826e-01,  8.03907495e-01],
                    [ 1.56633838e-01, -4.98433584e-01,  8.51320880e-01],
                    [-1.08471937e-02, -4.98511595e-01,  8.66022342e-01],
                    [-1.77902069e-01, -4.98559856e-01,  8.47441757e-01],
                    [-3.38103031e-01, -4.98576512e-01,  7.96298510e-01],
                    [-4.85307783e-01, -4.98560926e-01,  7.14554408e-01],
                    [-6.13855301e-01, -4.98513691e-01,  6.05345788e-01],
                    [-7.18801059e-01, -4.98436622e-01,  4.72871683e-01],
                    [-7.96109980e-01, -4.98332685e-01,  3.22227930e-01],
                    [-8.42815740e-01, -4.98205879e-01,  1.59207637e-01],
                    [-6.93028653e-01, -6.98043554e-01, -8.03614468e-03],
                    [-6.77952217e-01, -6.97916383e-01, -1.44516871e-01],
                    [-6.36808301e-01, -6.97784046e-01, -2.75439149e-01],
                    [-5.71187238e-01, -6.97651620e-01, -3.95783116e-01],
                    [-4.83603372e-01, -6.97524204e-01, -5.00911881e-01],
                    [-3.77419737e-01, -6.97406690e-01, -5.86788528e-01],
                    [-2.56713747e-01, -6.97303590e-01, -6.50115910e-01],
                    [-1.26135910e-01, -6.97218864e-01, -6.88467229e-01],
                    [ 9.30681864e-03, -6.97155773e-01, -7.00360069e-01],
                    [ 1.44404817e-01, -6.97116748e-01, -6.85330164e-01],
                    [ 2.73961899e-01, -6.97103284e-01, -6.43962440e-01],
                    [ 3.93010553e-01, -6.97115888e-01, -5.77854975e-01],
                    [ 4.96963788e-01, -6.97154085e-01, -4.89541678e-01],
                    [ 5.81829503e-01, -6.97216409e-01, -3.82413267e-01],
                    [ 6.44360957e-01, -6.97300462e-01, -2.60583303e-01],
                    [ 6.82129428e-01, -6.97403014e-01, -1.28745994e-01],
                    [ 6.93706796e-01, -6.97520124e-01,  8.04379771e-03],
                    [ 6.78630360e-01, -6.97647294e-01,  1.44524524e-01],
                    [ 6.37497408e-01, -6.97779628e-01,  2.75446766e-01],
                    [ 5.71865062e-01, -6.97912057e-01,  3.95790602e-01],
                    [ 4.84281516e-01, -6.98039473e-01,  5.00919534e-01],
                    [ 3.78097883e-01, -6.98156987e-01,  5.86796019e-01],
                    [ 2.57391894e-01, -6.98260087e-01,  6.50123237e-01],
                    [ 1.26814054e-01, -6.98344813e-01,  6.88474882e-01],
                    [-8.62867490e-03, -6.98407905e-01,  7.00367722e-01],
                    [-1.43726674e-01, -6.98446930e-01,  6.85337817e-01],
                    [-2.73283751e-01, -6.98460393e-01,  6.43969768e-01],
                    [-3.92332407e-01, -6.98447790e-01,  5.77862466e-01],
                    [-4.96285644e-01, -6.98409593e-01,  4.89549331e-01],
                    [-5.81151680e-01, -6.98347269e-01,  3.82420754e-01],
                    [-6.43671850e-01, -6.98263211e-01,  2.60590920e-01],
                    [-6.81451284e-01, -6.98160664e-01,  1.28753647e-01],
                    [-1.69002248e-01, -8.38610973e-01, -1.95967097e-03],
                    [-1.65330726e-01, -8.38579977e-01, -3.52259059e-02],
                    [-1.55304038e-01, -8.38547719e-01, -6.71398215e-02],
                    [-1.39305828e-01, -8.38515442e-01, -9.64712056e-02],
                    [-1.17956727e-01, -8.38484389e-01, -1.22090298e-01],
                    [-9.20694737e-02, -8.38455743e-01, -1.43023290e-01],
                    [-6.26500693e-02, -8.38430610e-01, -1.58462430e-01],
                    [-3.08198566e-02, -8.38409960e-01, -1.67808438e-01],
                    [ 2.18233306e-03, -8.38394588e-01, -1.70704075e-01],
                    [ 3.51115424e-02, -8.38385073e-01, -1.67043928e-01],
                    [ 6.66926775e-02, -8.38381789e-01, -1.56962631e-01],
                    [ 9.57080276e-02, -8.38384865e-01, -1.40845909e-01],
                    [ 1.21051606e-01, -8.38394174e-01, -1.19318868e-01],
                    [ 1.41738390e-01, -8.38409360e-01, -9.32123469e-02],
                    [ 1.56980820e-01, -8.38429846e-01, -6.35187109e-02],
                    [ 1.66187374e-01, -8.38454844e-01, -3.13817755e-02],
                    [ 1.69006023e-01, -8.38483390e-01,  1.95971648e-03],
                    [ 1.65334501e-01, -8.38514386e-01,  3.52259515e-02],
                    [ 1.55307814e-01, -8.38546644e-01,  6.71398670e-02],
                    [ 1.39309606e-01, -8.38578921e-01,  9.64710883e-02],
                    [ 1.17960505e-01, -8.38609974e-01,  1.22090181e-01],
                    [ 9.20732493e-02, -8.38638620e-01,  1.43023336e-01],
                    [ 6.26538470e-02, -8.38663752e-01,  1.58462313e-01],
                    [ 3.08239567e-02, -8.38684403e-01,  1.67808324e-01],
                    [-2.18919394e-03, -8.38699778e-01,  1.70703835e-01],
                    [-3.51074423e-02, -8.38709289e-01,  1.67043814e-01],
                    [-6.66888998e-02, -8.38712574e-01,  1.56962514e-01],
                    [-9.57042520e-02, -8.38709498e-01,  1.40845955e-01],
                    [-1.21047828e-01, -8.38700188e-01,  1.19318751e-01],
                    [-1.41734612e-01, -8.38685003e-01,  9.32122296e-02],
                    [-1.56977044e-01, -8.38664517e-01,  6.35187564e-02],
                    [-1.66183598e-01, -8.38639519e-01,  3.13818210e-02],
                    [-1.05883473e-01, -8.38230144e-01, -1.22777515e-03],
                    [-1.03582673e-01, -8.38210720e-01, -2.20737344e-02],
                    [-9.73005051e-02, -8.38190513e-01, -4.20648591e-02],
                    [-8.72740437e-02, -8.38170292e-01, -6.04388708e-02],
                    [-7.39018181e-02, -8.38150838e-01, -7.64900783e-02],
                    [-5.76894147e-02, -8.38132886e-01, -8.96127130e-02],
                    [-3.92491280e-02, -8.38117144e-01, -9.92778023e-02],
                    [-1.93109263e-02, -8.38104207e-01, -1.05133606e-01],
                    [ 1.36580348e-03, -8.38094576e-01, -1.06948251e-01],
                    [ 2.20005688e-02, -8.38088614e-01, -1.04654577e-01],
                    [ 4.17832352e-02, -8.38086558e-01, -9.83381885e-02],
                    [ 5.99702497e-02, -8.38088475e-01, -8.82483860e-02],
                    [ 7.58421566e-02, -8.38094316e-01, -7.47537165e-02],
                    [ 8.87990981e-02, -8.38103832e-01, -5.83972082e-02],
                    [ 9.83521157e-02, -8.38116663e-01, -3.97961618e-02],
                    [ 1.04120545e-01, -8.38132322e-01, -1.96653041e-02],
                    [ 1.05886901e-01, -8.38150210e-01,  1.22781609e-03],
                    [ 1.03586101e-01, -8.38169633e-01,  2.20737754e-02],
                    [ 9.73039331e-02, -8.38189840e-01,  4.20649000e-02],
                    [ 8.72774717e-02, -8.38210062e-01,  6.04389118e-02],
                    [ 7.39055684e-02, -8.38229516e-01,  7.64901230e-02],
                    [ 5.76928448e-02, -8.38247467e-01,  8.96125912e-02],
                    [ 3.92528804e-02, -8.38263210e-01,  9.92776842e-02],
                    [ 1.93143564e-02, -8.38276146e-01,  1.05133484e-01],
                    [-1.37301198e-03, -8.38285781e-01,  1.06948006e-01],
                    [-2.19971388e-02, -8.38291740e-01,  1.04654455e-01],
                    [-4.17794827e-02, -8.38293796e-01,  9.83380704e-02],
                    [-5.99668197e-02, -8.38291879e-01,  8.82482642e-02],
                    [-7.58384063e-02, -8.38286037e-01,  7.47537611e-02],
                    [-8.87956701e-02, -8.38276521e-01,  5.83972491e-02],
                    [-9.83486878e-02, -8.38263690e-01,  3.97962028e-02],
                    [-1.04117117e-01, -8.38248032e-01,  1.96653450e-02],
                    [-3.49777704e-01, -8.45825423e-01, -4.05585410e-03],
                    [-3.42177397e-01, -8.45761275e-01, -7.29022432e-02],
                    [-3.21424928e-01, -8.45694514e-01, -1.38951262e-01],
                    [-2.88320804e-01, -8.45627705e-01, -1.99666335e-01],
                    [-2.44138671e-01, -8.45563427e-01, -2.52701363e-01],
                    [-1.90560571e-01, -8.45504141e-01, -2.96022099e-01],
                    [-1.29673735e-01, -8.45452123e-01, -3.27980041e-01],
                    [-6.37982620e-02, -8.45409383e-01, -3.47323791e-01],
                    [ 4.52407382e-03, -8.45377562e-01, -3.53317794e-01],
                    [ 7.26836089e-02, -8.45357867e-01, -3.45741210e-01],
                    [ 1.38043903e-01, -8.45351071e-01, -3.24875711e-01],
                    [ 1.98094378e-01, -8.45357442e-01, -2.91515436e-01],
                    [ 2.50536704e-01, -8.45376709e-01, -2.46965337e-01],
                    [ 2.93358395e-01, -8.45408147e-01, -1.92921453e-01],
                    [ 3.24898402e-01, -8.45450556e-01, -1.31456796e-01],
                    [ 3.43953523e-01, -8.45502292e-01, -6.49461866e-02],
                    [ 3.49788438e-01, -8.45561369e-01,  4.05599107e-03],
                    [ 3.42188457e-01, -8.45625517e-01,  7.29020583e-02],
                    [ 3.21435987e-01, -8.45692278e-01,  1.38951240e-01],
                    [ 2.88331542e-01, -8.45759087e-01,  1.99666147e-01],
                    [ 2.44138766e-01, -8.45823369e-01,  2.52701377e-01],
                    [ 1.90571307e-01, -8.45882651e-01,  2.96022073e-01],
                    [ 1.29684471e-01, -8.45934669e-01,  3.27980015e-01],
                    [ 6.38093204e-02, -8.45977409e-01,  3.47323769e-01],
                    [-4.52397844e-03, -8.46009234e-01,  3.53317807e-01],
                    [-7.26725505e-02, -8.46028925e-01,  3.45741188e-01],
                    [-1.38033167e-01, -8.46035721e-01,  3.24875685e-01],
                    [-1.98083642e-01, -8.46029350e-01,  2.91515410e-01],
                    [-2.50536608e-01, -8.46010087e-01,  2.46965350e-01],
                    [-2.93347657e-01, -8.45978645e-01,  1.92921264e-01],
                    [-3.24887344e-01, -8.45936236e-01,  1.31456774e-01],
                    [-3.43942462e-01, -8.45884500e-01,  6.49460017e-02],
                    [-4.27320140e-01, -8.37562388e-01, -4.95500655e-03],
                    [-4.18031483e-01, -8.37484012e-01, -8.90699861e-02],
                    [-3.92677582e-01, -8.37402457e-01, -1.69753259e-01],
                    [-3.52238749e-01, -8.37320844e-01, -2.43922863e-01],
                    [-2.98255814e-01, -8.37242316e-01, -3.08712426e-01],
                    [-2.32816000e-01, -8.37169888e-01, -3.61643283e-01],
                    [-1.58422923e-01, -8.37106341e-01, -4.00678989e-01],
                    [-7.79416390e-02, -8.37054124e-01, -4.24312290e-01],
                    [ 5.52288798e-03, -8.37015247e-01, -4.31638619e-01],
                    [ 8.87856817e-02, -8.36991192e-01, -4.22378997e-01],
                    [ 1.68638262e-01, -8.36982890e-01, -3.96886539e-01],
                    [ 2.42009741e-01, -8.36990663e-01, -3.56137423e-01],
                    [ 3.06074508e-01, -8.37014209e-01, -3.01704891e-01],
                    [ 3.58382477e-01, -8.37052616e-01, -2.35682829e-01],
                    [ 3.96910190e-01, -8.37104424e-01, -1.60597564e-01],
                    [ 4.20190666e-01, -8.37167621e-01, -7.93503501e-02],
                    [ 4.27322800e-01, -8.37239799e-01,  4.95503739e-03],
                    [ 4.18034142e-01, -8.37318175e-01,  8.90700170e-02],
                    [ 3.92680246e-01, -8.37399729e-01,  1.69752964e-01],
                    [ 3.52241408e-01, -8.37481343e-01,  2.43922894e-01],
                    [ 2.98258474e-01, -8.37559870e-01,  3.08712457e-01],
                    [ 2.32818984e-01, -8.37632298e-01,  3.61643155e-01],
                    [ 1.58425905e-01, -8.37695846e-01,  4.00679023e-01],
                    [ 7.79443007e-02, -8.37748063e-01,  4.24312158e-01],
                    [-5.53086690e-03, -8.37786944e-01,  4.31638526e-01],
                    [-8.87830200e-02, -8.37810995e-01,  4.22378865e-01],
                    [-1.68635279e-01, -8.37819297e-01,  3.96886573e-01],
                    [-2.42006757e-01, -8.37811524e-01,  3.56137295e-01],
                    [-3.06071848e-01, -8.37787978e-01,  3.01704922e-01],
                    [-3.58379817e-01, -8.37749571e-01,  2.35682859e-01],
                    [-3.96907526e-01, -8.37697763e-01,  1.60597270e-01],
                    [-4.20188006e-01, -8.37634566e-01,  7.93503809e-02],
                    [-2.59953294e-01, -8.40555500e-01, -5.53927663e-02],
                    [-2.44186043e-01, -8.40504785e-01, -1.05566247e-01],
                    [ 1.44774423e-01, -8.40647725e-01,  2.24895532e-01],
                    [ 1.85474621e-01, -8.40602684e-01,  1.91982292e-01],
                    [-4.84681474e-02, -8.40288174e-01, -2.63863266e-01],
                    [ 3.43447113e-03, -8.40263998e-01, -2.68419254e-01],
                    [-1.04860594e-01, -8.40764002e-01,  2.46807595e-01],
                    [-1.50494851e-01, -8.40759175e-01,  2.21471726e-01],
                    [ 2.22861330e-01, -8.40287238e-01, -1.46562231e-01],
                    [ 2.46822250e-01, -8.40319451e-01, -9.98727423e-02],
                    [-2.65729737e-01, -8.40604243e-01, -3.08127670e-03],
                    [ 2.19042435e-01, -8.40553847e-01,  1.51686185e-01],
                    [-9.85099428e-02, -8.40320644e-01, -2.49166107e-01],
                    [-5.52099790e-02, -8.40758843e-01,  2.62660904e-01],
                    [ 1.90335263e-01, -8.40263348e-01, -1.87624570e-01],
                    [ 2.44191724e-01, -8.40503096e-01,  1.05566318e-01],
                    [-1.44779378e-01, -8.40360161e-01, -2.24895748e-01],
                    [-3.43942878e-03, -8.40743887e-01,  2.68419201e-01],
                    [ 1.50489895e-01, -8.40248710e-01, -2.21471942e-01],
                    [-2.46816569e-01, -8.40688430e-01,  9.98728129e-02],
                    [-2.61294441e-01, -8.40649130e-01,  4.93482979e-02],
                    [ 2.59958979e-01, -8.40452380e-01,  5.53925113e-02],
                    [-1.85468940e-01, -8.40405197e-01, -1.91982222e-01],
                    [ 4.84738304e-02, -8.40719707e-01,  2.63863173e-01],
                    [ 1.04866279e-01, -8.40243878e-01, -2.46807850e-01],
                    [-2.22855325e-01, -8.40720643e-01,  1.46562143e-01],
                    [ 2.65735418e-01, -8.40403639e-01,  3.08134725e-03],
                    [-2.19036429e-01, -8.40454034e-01, -1.51686273e-01],
                    [ 9.85156279e-02, -8.40687237e-01,  2.49165852e-01],
                    [ 5.52156620e-02, -8.40249038e-01, -2.62660996e-01],
                    [-1.90329582e-01, -8.40744533e-01,  1.87624641e-01],
                    [ 2.61300126e-01, -8.40358751e-01, -4.93485530e-02],
                    [-9.56393666e-01,  2.49091693e-01, -1.10907172e-02],
                    [-9.35613182e-01,  2.49267073e-01, -1.99315458e-01],
                    [-8.78870887e-01,  2.49449597e-01, -3.79888826e-01],
                    [-7.88366023e-01,  2.49632235e-01, -5.45864121e-01],
                    [-6.67566500e-01,  2.49807967e-01, -6.90855849e-01],
                    [-5.21119460e-01,  2.49970045e-01, -8.09300856e-01],
                    [-3.54645151e-01,  2.50112240e-01, -8.96641907e-01],
                    [-1.74546967e-01,  2.50229093e-01, -9.49532940e-01],
                    [ 1.22459482e-02,  2.50316094e-01, -9.65922712e-01],
                    [ 1.98574382e-01,  2.50369929e-01, -9.45206397e-01],
                    [ 3.77253857e-01,  2.50388499e-01, -8.88155145e-01],
                    [ 5.41442693e-01,  2.50371115e-01, -7.96979877e-01],
                    [ 6.84813143e-01,  2.50318429e-01, -6.75174281e-01],
                    [ 8.01864606e-01,  2.50232475e-01, -5.27424543e-01],
                    [ 8.88092798e-01,  2.50116546e-01, -3.59399933e-01],
                    [ 9.40194501e-01,  2.49975106e-01, -1.77564460e-01],
                    [ 9.56149478e-01,  2.49813592e-01,  1.10862478e-02],
                    [ 9.35368835e-01,  2.49638211e-01,  1.99310824e-01],
                    [ 8.78626701e-01,  2.49455688e-01,  3.79884194e-01],
                    [ 7.88121839e-01,  2.49273050e-01,  5.45859326e-01],
                    [ 6.67321992e-01,  2.49097318e-01,  6.90851213e-01],
                    [ 5.20875272e-01,  2.48935239e-01,  8.09296387e-01],
                    [ 3.54400640e-01,  2.48793045e-01,  8.96637434e-01],
                    [ 1.74313420e-01,  2.48676196e-01,  9.49528431e-01],
                    [-1.24901342e-02,  2.48589191e-01,  9.65918079e-01],
                    [-1.98807930e-01,  2.48535360e-01,  9.45201888e-01],
                    [-3.77498367e-01,  2.48516786e-01,  8.88150672e-01],
                    [-5.41686881e-01,  2.48534170e-01,  7.96975408e-01],
                    [-6.85057651e-01,  2.48586855e-01,  6.75169645e-01],
                    [-8.02108790e-01,  2.48672810e-01,  5.27419748e-01],
                    [-8.88336984e-01,  2.48788739e-01,  3.59395301e-01],
                    [-9.40438848e-01,  2.48930179e-01,  1.77559826e-01],
                    [-8.57611966e-01,  4.97413990e-01, -9.94547746e-03],
                    [-8.38973636e-01,  4.97571241e-01, -1.78710150e-01],
                    [-7.88107603e-01,  4.97734876e-01, -3.40599209e-01],
                    [-7.06964399e-01,  4.97898622e-01, -4.89405624e-01],
                    [-5.98657799e-01,  4.98056184e-01, -6.19406791e-01],
                    [-4.67352160e-01,  4.98201502e-01, -7.25602274e-01],
                    [-3.18098051e-01,  4.98328988e-01, -8.03908939e-01],
                    [-1.56635132e-01,  4.98433745e-01, -8.51322157e-01],
                    [ 1.08459021e-02,  4.98511757e-01, -8.66023782e-01],
                    [ 1.77900775e-01,  4.98560018e-01, -8.47443034e-01],
                    [ 3.38101417e-01,  4.98576674e-01, -7.96299954e-01],
                    [ 4.85306490e-01,  4.98561088e-01, -7.14555685e-01],
                    [ 6.13854007e-01,  4.98513853e-01, -6.05347065e-01],
                    [ 7.18799767e-01,  4.98436784e-01, -4.72873123e-01],
                    [ 7.96108689e-01,  4.98332847e-01, -3.22229370e-01],
                    [ 8.42825408e-01,  4.98206044e-01, -1.59208787e-01],
                    [ 8.57136659e-01,  4.98061231e-01,  9.93795388e-03],
                    [ 8.38498651e-01,  4.97903980e-01,  1.78702631e-01],
                    [ 7.87621660e-01,  4.97740341e-01,  3.40591399e-01],
                    [ 7.06478455e-01,  4.97576595e-01,  4.89397814e-01],
                    [ 5.98171854e-01,  4.97419033e-01,  6.19399144e-01],
                    [ 4.66866214e-01,  4.97273715e-01,  7.25594627e-01],
                    [ 3.17611785e-01,  4.97146229e-01,  8.03901125e-01],
                    [ 1.56149186e-01,  4.97041472e-01,  8.51314511e-01],
                    [-1.13318457e-02,  4.96963460e-01,  8.66015972e-01],
                    [-1.78386721e-01,  4.96915200e-01,  8.47435387e-01],
                    [-3.38587683e-01,  4.96898543e-01,  7.96292140e-01],
                    [-4.85792435e-01,  4.96914129e-01,  7.14548038e-01],
                    [-6.14339953e-01,  4.96961364e-01,  6.05339418e-01],
                    [-7.19285711e-01,  4.97038433e-01,  4.72865313e-01],
                    [-7.96594632e-01,  4.97142371e-01,  3.22221560e-01],
                    [-8.43300392e-01,  4.97269177e-01,  1.59201267e-01],
                    [-6.82469184e-01,  6.97481172e-01, -7.89293285e-03],
                    [-6.67291443e-01,  6.97184772e-01, -1.42121370e-01],
                    [-6.26254589e-01,  6.96568824e-01, -2.70596736e-01],
                    [-5.61033017e-01,  6.95715149e-01, -3.88410225e-01],
                    [-4.74631582e-01,  6.94780027e-01, -4.90722198e-01],
                    [-3.69731536e-01,  6.93867983e-01, -5.74318647e-01],
                    [-2.51133999e-01,  6.92940859e-01, -6.35157187e-01],
                    [-1.23365629e-01,  6.92093496e-01, -6.72076817e-01],
                    [ 8.18273991e-03,  6.91678603e-01, -6.83140683e-01],
                    [ 1.39926918e-01,  6.91218969e-01, -6.68073132e-01],
                    [ 2.66236455e-01,  6.91491365e-01, -6.27442305e-01],
                    [ 3.82445206e-01,  6.91793062e-01, -5.63465814e-01],
                    [ 4.84827519e-01,  6.92264471e-01, -4.77509781e-01],
                    [ 5.67589345e-01,  6.92582436e-01, -3.73389014e-01],
                    [ 6.29217050e-01,  6.93138481e-01, -2.54530957e-01],
                    [ 6.66444155e-01,  6.93460295e-01, -1.26032956e-01],
                    [ 6.78133831e-01,  6.93767570e-01,  7.86217242e-03],
                    [ 6.63019238e-01,  6.93221191e-01,  1.41446492e-01],
                    [ 6.22512994e-01,  6.92670450e-01,  2.69042971e-01],
                    [ 5.57860224e-01,  6.91903216e-01,  3.86436739e-01],
                    [ 4.72456956e-01,  6.91400843e-01,  4.88607542e-01],
                    [ 3.67904133e-01,  6.90777904e-01,  5.72164214e-01],
                    [ 2.50091768e-01,  6.90364255e-01,  6.33426942e-01],
                    [ 1.22779379e-01,  6.90021846e-01,  6.71116887e-01],
                    [-9.31148829e-03,  6.90457277e-01,  6.83125128e-01],
                    [-1.40537646e-01,  6.90883870e-01,  6.69025323e-01],
                    [-2.67322617e-01,  6.91810682e-01,  6.29142936e-01],
                    [-3.84338272e-01,  6.92849003e-01,  5.65583406e-01],
                    [-4.87055578e-01,  6.93901875e-01,  4.79568610e-01],
                    [-5.70811664e-01,  6.95032471e-01,  3.75283405e-01],
                    [-6.32997257e-01,  6.96098098e-01,  2.55992723e-01],
                    [-6.70732311e-01,  6.96944555e-01,  1.26603790e-01],
                    [-2.80870824e-01,  9.29862110e-01, -2.38404916e-03],
                    [-2.74034171e-01,  9.29602849e-01, -6.06060990e-02],
                    [-2.56579065e-01,  9.29538339e-01, -1.14169900e-01],
                    [-2.30414792e-01,  9.29060338e-01, -1.60922685e-01],
                    [-1.93242907e-01,  9.29156859e-01, -2.04717654e-01],
                    [-1.51341138e-01,  9.28532212e-01, -2.37671512e-01],
                    [-1.01830581e-01,  9.28357786e-01, -2.63248378e-01],
                    [-4.97857339e-02,  9.27947943e-01, -2.78064307e-01],
                    [ 6.05065529e-03,  9.28005723e-01, -2.82279939e-01],
                    [ 5.91002769e-02,  9.27609766e-01, -2.75851049e-01],
                    [ 1.11822464e-01,  9.27679484e-01, -2.58246594e-01],
                    [ 1.58115470e-01,  9.27576754e-01, -2.31952258e-01],
                    [ 2.01380945e-01,  9.27895646e-01, -1.94852374e-01],
                    [ 2.33915755e-01,  9.27557349e-01, -1.52773806e-01],
                    [ 2.58137896e-01,  9.27946190e-01, -1.05349155e-01],
                    [ 2.73903367e-01,  9.27838135e-01, -4.97717335e-02],
                    [ 2.78515723e-01,  9.28031384e-01,  2.34300530e-03],
                    [ 2.72031072e-01,  9.27752019e-01,  5.84271262e-02],
                    [ 2.55285690e-01,  9.27741535e-01,  1.11485556e-01],
                    [ 2.29923781e-01,  9.27290190e-01,  1.58160363e-01],
                    [ 1.96628000e-01,  9.27511165e-01,  1.99158864e-01],
                    [ 1.51660003e-01,  9.27201557e-01,  2.35869410e-01],
                    [ 1.05469558e-01,  9.27150761e-01,  2.60719748e-01],
                    [ 5.21172382e-02,  9.27104704e-01,  2.77116033e-01],
                    [-1.02183356e-03,  9.27349430e-01,  2.82739762e-01],
                    [-5.75915257e-02,  9.27516744e-01,  2.76630749e-01],
                    [-1.08637596e-01,  9.27900282e-01,  2.60761421e-01],
                    [-1.57648998e-01,  9.28164571e-01,  2.33856501e-01],
                    [-1.98236732e-01,  9.28708350e-01,  2.00503211e-01],
                    [-2.34710909e-01,  9.28810077e-01,  1.55154874e-01],
                    [-2.59297791e-01,  9.29339516e-01,  1.08305381e-01],
                    [-2.75418303e-01,  9.29521947e-01,  5.42648076e-02],
                    [-4.67572058e-01,  8.50985950e-01, -1.00825071e-01],
                    [-4.38772629e-01,  8.51023491e-01, -1.91205308e-01],
                    [ 3.32240202e-01,  8.46901615e-01,  3.42708937e-01],
                    [ 2.59299478e-01,  8.46615363e-01,  4.01836527e-01],
                    [-8.63865636e-02,  8.47507294e-01, -4.72669749e-01],
                    [ 6.82081142e-03,  8.47485610e-01, -4.80473566e-01],
                    [-1.87235807e-01,  8.47313882e-01,  4.42862574e-01],
                    [-2.69339265e-01,  8.48219318e-01,  3.97946880e-01],
                    [ 3.98811401e-01,  8.47940393e-01, -2.61628445e-01],
                    [ 4.41845301e-01,  8.48412173e-01, -1.77693605e-01],
                    [-4.78383978e-01,  8.51352299e-01, -6.77230507e-03],
                    [ 3.91983385e-01,  8.47464446e-01,  2.70795596e-01],
                    [-1.75840676e-01,  8.48109411e-01, -4.47075344e-01],
                    [-9.84636038e-02,  8.46675114e-01,  4.70523611e-01],
                    [ 3.40916662e-01,  8.47507345e-01, -3.34906023e-01],
                    [ 4.37164300e-01,  8.48085378e-01,  1.87883654e-01],
                    [-2.59133215e-01,  8.48828252e-01, -4.04208593e-01],
                    [-5.48371925e-03,  8.46637387e-01,  4.80486369e-01],
                    [ 2.69511557e-01,  8.47328300e-01, -3.95707380e-01],
                    [-4.43788593e-01,  8.50485179e-01,  1.81099916e-01],
                    [-4.70014969e-01,  8.50815403e-01,  8.99616114e-02],
                    [ 4.65079293e-01,  8.48013750e-01,  9.81381749e-02],
                    [-3.32458118e-01,  8.49526111e-01, -3.45533597e-01],
                    [ 8.70628534e-02,  8.46129421e-01,  4.71931846e-01],
                    [ 1.87946340e-01,  8.47099340e-01, -4.41217879e-01],
                    [-3.99956908e-01,  8.49768531e-01,  2.64442961e-01],
                    [ 4.75348680e-01,  8.48509979e-01,  6.71274554e-03],
                    [-3.93077553e-01,  8.50238744e-01, -2.73652075e-01],
                    [ 1.76593181e-01,  8.46306741e-01,  4.45442210e-01],
                    [ 9.91208605e-02,  8.46971228e-01, -4.69775484e-01],
                    [-3.41206769e-01,  8.48915340e-01,  3.37719386e-01],
                    [ 4.67454073e-01,  8.48179541e-01, -8.73276523e-02],
                    [-2.78458428e-02,  9.61180335e-01,  1.22933557e-01],
                    [-4.85067998e-02,  9.61286669e-01,  1.15907582e-01],
                    [-6.83837708e-02,  9.61211307e-01,  1.06836295e-01],
                    [-8.79935587e-02,  9.62008353e-01,  8.95065286e-02],
                    [-1.04922692e-01,  9.61759102e-01,  7.07323440e-02],
                    [-1.16271845e-01,  9.61830432e-01,  4.62530784e-02],
                    [-1.22699899e-01,  9.61814217e-01,  2.52622619e-02],
                    [-1.22189021e-01,  9.61893548e-01, -2.73288175e-02],
                    [-1.13756939e-01,  9.61799985e-01, -5.21470241e-02],
                    [-1.06401433e-01,  9.61827797e-01, -6.80823599e-02],
                    [-8.36269212e-02,  9.61934941e-01, -9.34992857e-02],
                    [-6.85508229e-02,  9.61649702e-01, -1.06580056e-01],
                    [-4.43831672e-02,  9.61419971e-01, -1.17424467e-01],
                    [-2.38223120e-02,  9.61390355e-01, -1.23710116e-01],
                    [-1.25052218e-01,  9.62247846e-01, -1.42958306e-03],
                    [ 2.59349232e-02,  9.61149434e-01, -1.22947515e-01],
                    [ 5.08473275e-02,  9.61010836e-01, -1.14200353e-01],
                    [ 6.66130733e-02,  9.61031954e-01, -1.06793913e-01],
                    [ 9.11859430e-02,  9.61324144e-01, -8.42378602e-02],
                    [ 1.04432000e-01,  9.61055885e-01, -6.84678095e-02],
                    [ 1.14998645e-01,  9.60973791e-01, -4.45441121e-02],
                    [ 1.20809955e-01,  9.60937299e-01, -2.52432463e-02],
                    [ 3.08806969e-03,  9.61575578e-01, -1.25693158e-01],
                    [ 1.20300172e-01,  9.60912016e-01,  2.72602373e-02],
                    [ 1.13533487e-01,  9.60912612e-01,  4.79231623e-02],
                    [ 1.04502346e-01,  9.60729200e-01,  6.79918404e-02],
                    [ 8.71058554e-02,  9.61363863e-01,  8.82256913e-02],
                    [ 6.85160793e-02,  9.60876646e-01,  1.05352866e-01],
                    [ 4.47115639e-02,  9.60976336e-01,  1.16573254e-01],
                    [ 2.39618436e-02,  9.60865038e-01,  1.23261048e-01],
                    [-1.30864610e-04,  9.61264339e-01,  1.25702753e-01],
                    [ 1.23151256e-01,  9.61281956e-01,  1.44847033e-03],
                    [ 1.47801402e-03,  9.61765898e-01,  3.76033347e-05],
                ],
                dtype=np.float32,
            )
        self.num_face = 1103
        self.num_eye = 481
        self.input_size = 160
        session_option = onnxruntime.SessionOptions()
        session_option.log_severity_level = 3
        session_option.intra_op_num_threads = psutil.cpu_count(logical=True) - 1
        self.onnx_session = onnxruntime.InferenceSession(
            model_path,
            sess_options=session_option,
            providers=providers,
        )
        self.input_shapes = [
            input.shape for input in self.onnx_session.get_inputs()
        ]
        self.input_names = [
            input.name for input in self.onnx_session.get_inputs()
        ]
        self.output_names = [
            output.name for output in self.onnx_session.get_outputs()
        ]
        self.enable_3d_rendering = enable_3d_rendering

    def draw_item(self, eimg, item):
        #bbox, kps, eye_kps = item
        eye_kps = item
        eye_l = eye_kps[:self.num_eye,:]
        eye_r = eye_kps[self.num_eye:,:]
        for _eye in [eye_l, eye_r]:
            tmp = _eye[:,0].copy()
            _eye[:,0] = _eye[:,1].copy()
            _eye[:,1] = tmp

        if self.enable_3d_rendering:
            for _eye in [eye_l, eye_r]:
                _kps = _eye[self.iris_idx_481,:].astype(np.int32)
                for l in range(_kps.shape[0]):
                    color = (0, 255, 0)
                    cv2.circle(eimg, (_kps[l][1], _kps[l][0]), 4, color, 4)
                for _tri in self.tri481:
                    color = (0, 0, 255)
                    for k in range(3):
                        ix = _tri[k]
                        iy = _tri[(k+1)%3]
                        x = _eye[ix,:2].astype(np.int32)[::-1]
                        y = _eye[iy,:2].astype(np.int32)[::-1]
                        cv2.line(eimg, x, y, color, 1)

        theta_x_l, theta_y_l, vec_l = angles_and_vec_from_eye(eye_l, self.iris_idx_481)
        theta_x_r, theta_y_r, vec_r = angles_and_vec_from_eye(eye_r, self.iris_idx_481)
        gaze_pred = np.array([(theta_x_l + theta_x_r) / 2, (theta_y_l + theta_y_r) / 2])

        diag = np.sqrt(float(eimg.shape[0]*eimg.shape[1]))

        eye_pos_left = eye_l[self.iris_idx_481].mean(axis=0)[[0, 1]]
        eye_pos_right = eye_r[self.iris_idx_481].mean(axis=0)[[0, 1]]

        ## pred
        gaze_pred = np.array([theta_x_l, theta_y_l])
        dx = 0.4*diag * np.sin(gaze_pred[1])
        dy = 0.4*diag * np.sin(gaze_pred[0])
        x = np.array([eye_pos_left[1], eye_pos_left[0]])
        y = x.copy()
        y[0] += dx
        y[1] += dy
        x = x.astype(np.int32)
        y = y.astype(np.int32)
        color = (0,255,0)
        cv2.line(eimg, x, y, color, 5)
        # Yaw, Pitch
        yaw_deg_l = theta_y_l * (180 / np.pi)
        pitch_deg_l = -(theta_x_l * (180 / np.pi))


        gaze_pred = np.array([theta_x_r, theta_y_r])
        dx = 0.4*diag * np.sin(gaze_pred[1])
        dy = 0.4*diag * np.sin(gaze_pred[0])
        x = np.array([eye_pos_right[1], eye_pos_right[0]])
        y = x.copy()
        y[0] += dx
        y[1] += dy
        x = x.astype(np.int32)
        y = y.astype(np.int32)
        color = (0,255,0)
        cv2.line(eimg, x, y, color, 5)
        # Yaw, Pitch
        yaw_deg_r = theta_y_r * (180 / np.pi)
        pitch_deg_r = -(theta_x_r * (180 / np.pi))
        return eimg, yaw_deg_l, pitch_deg_l, yaw_deg_r, pitch_deg_r

    def draw_on(self, eimg, results, elapsed_time):
        face_sizes = [ (x[0][2] - x[0][0]) for x in results]
        max_index = np.argmax(face_sizes)
        max_face_size = face_sizes[max_index]
        rescale = 300.0 / max_face_size
        oimg = eimg.copy()
        eimg = cv2.resize(eimg, None, fx=rescale, fy=rescale)
        for pred in results:
            _, _, eye_kps = pred
            eye_kps = eye_kps.copy()
            eye_kps *= rescale
            eimg, yaw_deg_l, pitch_deg_l, yaw_deg_r, pitch_deg_r = self.draw_item(eimg, eye_kps)
        eimg = cv2.resize(eimg, (oimg.shape[1], oimg.shape[0]))
        # Yaw, Pitch
        cv2.putText(
            eimg,
            f"L-Yaw  : {yaw_deg_l:5.2f}",
            (int(eimg.shape[1]-200), 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 3,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"L-Yaw  : {yaw_deg_l:5.2f}",
            (int(eimg.shape[1]-200), 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"L-Pitch : {pitch_deg_l:5.2f}",
            (int(eimg.shape[1]-200), 60), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 3,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"L-Pitch : {pitch_deg_l:5.2f}",
            (int(eimg.shape[1]-200), 60), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"R-Yaw  : {yaw_deg_r:5.2f}",
            (int(eimg.shape[1]-200), 90), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 3,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"R-Yaw  : {yaw_deg_r:5.2f}",
            (int(eimg.shape[1]-200), 90), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"R-Pitch : {pitch_deg_r:5.2f}",
            (int(eimg.shape[1]-200), 120), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 3,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            f"R-Pitch : {pitch_deg_r:5.2f}",
            (int(eimg.shape[1]-200), 120), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2,
            cv2.LINE_AA,
        )

        # Inference elapsed time
        cv2.putText(
            eimg,
            "Elapsed Time : " + '{:.1f}'.format(elapsed_time * 1000) + "ms",
            (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 3,
            cv2.LINE_AA,
        )
        cv2.putText(
            eimg,
            "Elapsed Time : " + '{:.1f}'.format(elapsed_time * 1000) + "ms",
            (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2,
            cv2.LINE_AA,
        )
        return eimg

    def get(self, img):
        results = []
        batchno_classid_score_x1y1x2y2_landms = self.detector(img)
        if len(batchno_classid_score_x1y1x2y2_landms)==0:
            return results
        image_width = img.shape[1]
        image_height = img.shape[0]
        face_imgs = []
        face_kps = []
        Ms = []
        for face in batchno_classid_score_x1y1x2y2_landms:
            x_min = max(int(face[3]), 0)
            y_min = max(int(face[4]), 0)
            x_max = min(int(face[5]), image_width)
            y_max = min(int(face[6]), image_height)

            bbox = [x_min, y_min, x_max, y_max]
            kps = face[7:]
            kps_right_eye = np.asarray([int(face[7]), int(face[8])], dtype=np.int32) # [x, y]
            kps_left_eye = np.asarray([int(face[9]), int(face[10])], dtype=np.int32) # [x, y]
            width = x_max - x_min
            center = (kps_left_eye + kps_right_eye) / 2.0 # (lx + rx) / 2, (ly + ry) / 2

            _size = max(width/1.5, np.abs(kps_right_eye[0] - kps_left_eye[0]) ) * 1.5
            rotate = 0
            _scale = self.input_size  / _size
            aimg, M = transform(img, center, self.input_size, _scale, rotate)
            aimg = cv2.cvtColor(aimg, cv2.COLOR_BGR2RGB)

            face_imgs.append(aimg)
            face_kps.append(kps)
            Ms.append(M)

        input_face_images = np.asarray(face_imgs, dtype=np.float32)
        input_face_images = input_face_images.transpose([0,3,1,2])
        input_face_images = (input_face_images / 255.0 - 0.5) / 0.5

        opreds = \
            self.onnx_session.run(
                self.output_names,
                {input_name: input_face_images for input_name in self.input_names},
            )[0]

        for opred, face_kp, M in zip(opreds, face_kps, Ms):
            IM = cv2.invertAffineTransform(M)
            pred = trans_points(opred, IM)
            result = (bbox, face_kp, pred)
            results.append(result)

        return results


def main():
    parser = argparse.ArgumentParser()

    parser.add_argument(
        '-d',
        '--device',
        type=int,
        default=0,
    )
    parser.add_argument(
        '-mov',
        '--movie',
        type=str,
        default=None,
    )
    parser.add_argument(
        '-dm',
        '--detector_model',
        type=str,
        default='retinaface_mbn025_with_postprocess_480x640_max1000_th0.70.onnx',
    )
    parser.add_argument(
        '-pm',
        '--predictor_model',
        type=str,
        default='generalizing_gaze_estimation_with_weak_supervision_from_synthetic_views_Nx3x160x160.onnx',
    )
    parser.add_argument(
        '-p',
        '--provider',
        type=str,
        default='cuda',
        choices=['cpu','cuda','tensorrt'],
    )
    parser.add_argument(
        '-etr',
        '--enable_3d_rendering',
        action='store_true',
    )
    args = parser.parse_args()

    cap_device: int = args.device
    if args.movie is not None:
        cap_device = args.movie

    providers = None
    if args.provider == 'cpu':
        providers = [
            'CPUExecutionProvider',
        ]
    elif args.provider == 'cuda':
        providers = [
            'CUDAExecutionProvider',
            'CPUExecutionProvider',
        ]
    elif args.provider == 'tensorrt':
        providers = [
            (
                'TensorrtExecutionProvider', {
                    'trt_engine_cache_enable': True,
                    'trt_engine_cache_path': '.',
                    'trt_fp16_enable': True,
                }
            ),
            'CUDAExecutionProvider',
            'CPUExecutionProvider',
        ]
    enable_3d_rendering: bool = args.enable_3d_rendering

    cap = cv2.VideoCapture(cap_device)
    cap_width = 640
    cap_height = 480
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, cap_width)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, cap_height)
    cap_fps = cap.get(cv2.CAP_PROP_FPS)
    fourcc = cv2.VideoWriter.fourcc('m','p','4','v')
    video_writer = cv2.VideoWriter(
        filename='output.mp4',
        fourcc=fourcc,
        fps=cap_fps,
        frameSize=(cap_width, cap_height),
    )

    detector = RetinaFaceONNX(
        model_path=args.detector_model,
        providers=providers,
    )
    handler = GazeHandler(
        detector=detector,
        model_path=args.predictor_model,
        providers=providers,
        enable_3d_rendering=enable_3d_rendering,
    )
    while True:
        # Capture read
        ret, frame = cap.read()
        if not ret:
            break

        debug_image = copy.deepcopy(frame)
        debug_image = cv2.resize(debug_image, (640,480))

        start_time = time.time()
        results = handler.get(debug_image)
        elapsed_time = time.time() - start_time

        if len(results) > 0:
            debug_image = handler.draw_on(debug_image, results, elapsed_time)
        video_writer.write(debug_image)
        cv2.imshow('Generalizing Gaze Estimation', debug_image)
        key = cv2.waitKey(1) \
            if args.movie is None or args.movie[-4:] == '.mp4' else cv2.waitKey(0)
        if key == 27:  # ESC
            break

    if video_writer:
        video_writer.release()
    if cap:
        cap.release()
    cv2.destroyAllWindows()

if __name__ == '__main__':
    main()

